Circle and Emplyee Prog - Exam

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

class Circle {

double x_co;
double y_co;
double radius;

Circle() {
x_co = 0;
y_co = 0;
radius = 1;
}

Circle(double x, double y, double r) {


x_co = x;
y_co = y;
radius = r;
}

double calculateArea() {
return Math.PI * radius * radius;
}

boolean isEqual(Circle tmp) {


return x_co == tmp.x_co && y_co == tmp.y_co && radius == tmp.radius;
}
}

class op {
public static void main(String[] args) {

Circle circles[]=new Circle[3];


circles[0]=new Circle();
circles[1]=new Circle(1,2,3);
circles[2]=new Circle();
int j=1;

for (Circle obj : circles) {


System.out.println("Area of Circle " + j++ +" : "+ obj.calculateArea());

if (circles[0].isEqual(circles[1])) {
System.out.println("Circle 1 and Circle 2 are equal.");
} else {
System.out.println("Circle 1 and Circle 2 are not equal.");
}

}
}
class Employee {
String empId;
double basicSalary;

Employee(String empId, double basicSalary) {


this.empId = empId;
this.basicSalary = basicSalary;
}

void displayInfo() {
System.out.println("Employee ID: " + empId);
System.out.println("Basic Salary: " + basicSalary);
}

class RegularEmployee extends Employee {


RegularEmployee(String empId, double basicSalary) {
super(empId, basicSalary);
}

void displayInfo() {
super.displayInfo();
System.out.println("Total Salary: " + 1.4*basicSalary );

}
}

class TemporaryEmployee extends Employee {


TemporaryEmployee(String empId, double basicSalary) {
super(empId, basicSalary);
}

void displayInfo() {
super.displayInfo();
System.out.println("Total Salary: " + 1.2*basicSalary );
}
}
public class firsttest{
public static void main(String[] args) {
// perform runtime polymorphism as asked in question
Employee E;
RegularEmployee regularEmp = new RegularEmployee("R001", 50000);
E=regularEmp;
E.displayInfo();

System.out.println();

TemporaryEmployee temporaryEmp = new TemporaryEmployee("T001", 30000);


E=temporaryEmp;
E.displayInfo();

}
}

You might also like