0% found this document useful (0 votes)
15 views4 pages

Untitled Document

The document contains Java code for three tasks: Task 7 implements a simple employee management system with classes for person and employee, Task 9 defines classes for calculating the area of a rectangle and a circle, and Task 11 demonstrates synchronized printing of numbers in odd and even threads. Each task includes code snippets and their respective outputs. The author is Preeth Poojary, a student in the COMP-B branch.

Uploaded by

myfakeemailidlol
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Untitled Document

The document contains Java code for three tasks: Task 7 implements a simple employee management system with classes for person and employee, Task 9 defines classes for calculating the area of a rectangle and a circle, and Task 11 demonstrates synchronized printing of numbers in odd and even threads. Each task includes code snippets and their respective outputs. The author is Preeth Poojary, a student in the COMP-B branch.

Uploaded by

myfakeemailidlol
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name:- Preeth Poojary Roll No: 1025228 Branch:COMP-B Batch:2 Date: Task 7

import [Link].*;
class person
{
String name;
int age;
person(String name, int age)
{
[Link] = name;
[Link] = age;
}
void displayperson()
{
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}
class employee extends person
{
int empid;
String department;

employee(String name, int age, int empid, String department)


{
super(name, age);
[Link] = empid;
[Link] = department;
}
void displayemployee()
{
displayperson();
[Link]("Employee ID: " + empid);
[Link]("Department: " + department);
}
}
class EmployeeManagement
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter name: ");
String name = [Link]();
[Link]("Enter Age: ");
int age = [Link]();
[Link]("Enter Employee ID: ");
int empid = [Link]();
[Link]();
[Link]("Enter Department: ");
String department = [Link]();
employee emp = new employee(name, age, empid, department);
[Link]("Employee Details:");
[Link]();
}
}
Enter name: Preeth
Enter Age: 21
Enter Employee ID: 1025213
Enter Department: Computer Engineering

Employee Details:
Name: Preeth
Age: 21
Employee ID: 1025213
Department: Computer Engineering
Name:- Preeth Poojary Roll No: 1025228 Branch:COMP-B Batch:2 Date: Task 9

CODE:
package [Link];
public class Rectangle {
private double length;
private double breadth;
public Rectangle(double length, double breadth) {
[Link] = length;
[Link] = breadth;
}
public double calculateArea() {
return length * breadth;
}
}
package [Link];
public class Circle {
private double radius;
public Circle(double radius) {
[Link] = radius;
}
public double calculateArea() {
return [Link] * radius * radius;
}
}
import [Link];
import [Link];
public class TestShapes {
public static void main(String[] args) {
Rectangle rect = new Rectangle(10, 5);
[Link]("Rectangle Area: " + [Link]());
Circle circ = new Circle(7);
[Link]("Circle Area: " + [Link]());
}
}
OUTPUT:
Z:\> cd java
Z:\java> javac -d . [Link]
Z:\java> javac -d . [Link]
Z:\java> javac [Link]
Z:\java> java TestShapes

Rectangle Area: 50.0


Circle Area: 153.93804002589985
Name:- Preeth Poojary Roll No: 1025228 Branch:COMP-B Batch:2 Date: Task 11

CODE:​
class PrintNumbers
{
int num = 1;
synchronized void print(int remainder)
{
while (num <= 10)
{
while (num % 2 != remainder)
{
try
{
wait();
}
catch (Exception e)
{
}
}
[Link](num);
num++;
notify();
}
}
}
public class DEMO
{
public static void main(String[] args)
{
PrintNumbers obj = new PrintNumbers();
Thread odd = new Thread(() -> [Link](1));
Thread even = new Thread(() -> [Link](0));
[Link]();
[Link]();
}
}
OUTPUT:
1
2
3
4
5
6
7
8
9
10

You might also like