0% found this document useful (0 votes)
19 views3 pages

Person

The document defines four Java classes - Person, Employee, PartTimeEmployee and FullTimeEmployee. Person defines basic attributes like name, age and address. Employee extends Person and adds department and designation attributes. PartTimeEmployee extends Employee and adds hours and rate attributes to calculate salary. FullTimeEmployee extends Employee and adds basic pay and allowance attributes to calculate salary. The Main class creates objects of both employee types and prints their details and salaries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Person

The document defines four Java classes - Person, Employee, PartTimeEmployee and FullTimeEmployee. Person defines basic attributes like name, age and address. Employee extends Person and adds department and designation attributes. PartTimeEmployee extends Employee and adds hours and rate attributes to calculate salary. FullTimeEmployee extends Employee and adds basic pay and allowance attributes to calculate salary. The Main class creates objects of both employee types and prints their details and salaries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

*Person

public class person {


private String name;
private int age;
private String address;

public person(int age,String name,String address){


this.name=name;
this.age=age;
this.address=address;
}
public int getAge(){
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;

}
}

*Employee
public class Employee extends person {
private String Department;
private String Designation;

public Employee(String name,int age,String address,String Designation,String


Department) {
super(age,name,address);
this.Department=Department;
this.Designation=Designation;
}
public String getDepartment() {
return Department;
}
public void setDepartment(String department) {
this.Department = department;
}
public String getDesignation() {
return Designation;
}
public void setDesignation(String designation) {
this.Designation = designation;
}
}
*Part-Time Employee
public class ParttimeEmployee extends Employee {
private double hours;
private double rate;

public ParttimeEmployee(String name,int age,String address,String


Designation,String Department,double hours,double rate) {
super(name,age,address,Department,Designation);
this.hours=hours;
this.rate=rate;
}
public double getHours() {
return hours;
}
public void setHours(double hours) {
this.hours = hours;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public String toString() {
return "Name: "+ getName() + "\n" + "Age: "+ getAge() + "\n"
+"Address: "+ getAddress() + "\n" + "Dpartment: "+ getDepartment() + "\n"
+"Designation: "+ getDesignation()
+ "\n"+ "Hours: "+ this.hours+ "\n"+ "Rate: "+ this.rate ;
}
public double salary () {

return hours*rate;
}
}
*Full-Time Employee
public class FulltimeEmployee extends Employee{
private double basic;
private double allowance;

public FulltimeEmployee(String name,int age,String address,String


Designation,String Department,double basic,double allowance){
super(name,age,address,Department,Designation);
this.basic=basic;
this.allowance=allowance;
}
public void setBasic(double b) {
this.basic=b;
}
public void setAllowance(double a) {
this.allowance=a;
}
public double getBasic() {
return basic;
}
public double getAllowance() {
return allowance;
}

public String toString() {


return "Name: "+ getName() + "\n" + "Age: "+ getAge() + "\n" +"Address: "+
getAddress() + "\n" + "Dpartment: "+ getDepartment() + "\n" +"Designation: "+
getDesignation()
+ "\n"+ "basis: "+ this.basic + "\n"+ "Allowance: "+ this.allowance ;
}
public double salary () {

return ((allowance/100)*basic)+basic;
}
}

*Main
public class Main {
public static void main(String[] args) {
ParttimeEmployee pt = new ParttimeEmployee("Abcd", 35, "North south
university", "Cse",
"Professor", 2.5, 300.0);

System.out.println(pt);
System.out.println("Salary: " + pt.salary());
System.out.println();

FulltimeEmployee et = new FulltimeEmployee("bcd", 36, "North south university",


"Cse",
"Professor", 19000, 25);

System.out.println(et);
System.out.println("Salary: " + et.salary());
}
}

You might also like