Program in Java (The Person, Student, Employee, Faculty, and Staff classes) Desi
ID: 3853661 • Letter: P
Question
Program in Java
Explanation / Answer
Person.java
public abstract class Person {
// Declaring variables
private String name;
private String address;
private String phoneNo;
private String email;
public Person(String name, String address, String phoneNo, String email) {
super();
this.name = name;
this.address = address;
this.phoneNo = phoneNo;
this.email = email;
}
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;
}
public String getPhoneNo() {
return phoneNo;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public abstract String toString();
}
__________________
Student.java
public class Student extends Person {
private String classStatus;
public Student(String name, String address, String phoneNo, String email,String classStatus) {
super(name, address, phoneNo, email);
this.classStatus = classStatus;
}
@Override
public String toString() {
return "Student [Name :"+super.getName()+"]";
}
}
_________________________
Employee.java
public class Employee extends Person {
// Declaring variables
private String office;
private double salary;
private MyDate dateHired;
public Employee(String name, String address, String phoneNo, String email,
String office, double salary, MyDate dateHired) {
super(name, address, phoneNo, email);
this.office = office;
this.salary = salary;
this.dateHired = dateHired;
}
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public MyDate getDateHired() {
return dateHired;
}
public void setDateHired(MyDate dateHired) {
this.dateHired = dateHired;
}
@Override
public String toString() {
return "Employee [Name" + super.getName() + "]";
}
}
_____________________
Faculty.java
public class Faculty extends Employee {
private int officeHours;
private int rank;
public Faculty(String name, String address, String phoneNo, String email,
String office, double salary, MyDate dateHired, int officeHours,
int rank) {
super(name, address, phoneNo, email, office, salary, dateHired);
this.officeHours = officeHours;
this.rank = rank;
}
public int getOfficeHours() {
return officeHours;
}
public void setOfficeHours(int officeHours) {
this.officeHours = officeHours;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
@Override
public String toString() {
return "Faculty [Name =" + super.toString() + "]";
}
}
_______________________
Staff.java
public class Staff extends Employee {
//Declaring variables
private String title;
public Staff(String name, String address, String phoneNo, String email,
String office, double salary, MyDate dateHired, String title) {
super(name, address, phoneNo, email, office, salary, dateHired);
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return "Staff [Name =" + super.getName() + "]";
}
}
____________________
MyDate.java
public class MyDate {
private int year;
private int month;
private int day;
public MyDate(int year, int month, int day) {
super();
this.year = year;
this.month = month;
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
@Override
public String toString() {
return "Year=" + year + ", Month=" + month + ", Day=" + day;
}
}
____________________________
Test.java
public class Test {
public static void main(String[] args) {
Student st = new Student("Williams", "103,Park Street", "9848425878","williams123gail.com", "Junior");
// Displaying the Student Details
System.out.println(st.toString());
MyDate dateHired = new MyDate(2007, 06, 06);
Employee emp = new Employee("Johnson", "101,Pearl Street","9019208993", "johnson222gail.com", "Microsoft", 50000,dateHired);
// Displaying the Employee Details
System.out.println(emp.toString());
MyDate dateHired1 = new MyDate(2002, 05, 06);
Faculty f=new Faculty("Nicole","304,church road","9666242333","nicole12gail.com", "Wipro", 65000, dateHired1, 8, 3);
// Displaying the Faculty Details
System.out.println(f.toString());
MyDate dateHired2 = new MyDate(2005, 07,21);
Staff stf=new Staff("Sunny","302,Villa mary's road", "9884561234","sunny12gail.com","Tata Consultancy", 75000, dateHired2,"Manager");
// Displaying the Staff Details
System.out.println(stf.toString());
}
}
______________________
Output:
Student [Name :Williams]
Employee [NameJohnson]
Faculty [Name =Employee [NameNicole]]
Staff [Name =Sunny]
__________________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.