Question
(The Person , Student , Employee , Faculty , and Staff classes) Design a class named Person and its two subclasses named Student and Employee
(The Person , Student , Employee , Faculty , and Staff classes)
Design a class named Person and its two subclasses named Student and Employee .
A person has a name, address, phone number, and email address.
A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant.
An employee has an office, salary, and date hired.
Use the MyDate class defined in Programming Exercise 10.14 to create an object for date hired.
Make Faculty and Staff subclasses of Employee .
A faculty member has office hours and a rank.
A staff member has a title. Override the toString method in each class to display the class name and the persons name.
Write a test program that creates a Person , Student , Employee , Faculty , and Staff , and invokes their toString() methods.
I cant get this program to run. I end up with everything being null.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
public class PersonMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Person p1 = new Person();
Student s1 = new Student();
Employee e1 = new Employee();
Faculty f1 = new Faculty();
Staff st1 = new Staff();
//String Person = p1.toString();
//String Student = s1.toString();
//String Employee = e1.toString();
//String Faculty = f1.toString();
//String Staff = st1.toString();
//System.out.println(Person);
//System.out.println(Student);
//System.out.println(Employee);
//System.out.println(Faculty);
//System.out.println(Staff);
System.out.println(p1.toString());
System.out.println(s1.toString());
System.out.println(e1.toString());
System.out.println(f1.toString());
System.out.println(st1.toString());
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
public class Person {
// Declaring variables
private String name, address;
private String phoneNo;
private String email;
// Zero Argument Constructor
public Person() {
super();
}
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;
}
@Override
public String toString() {
return "Name=" + name + ", Address=" + address + ", Phone No="
+ phoneNo + ", email=" + email;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
public class Student extends Person {
public static final String CLASS_STATUS = "Freshman";
@Override
public String toString() {
return "Class: Student " + " Class Status: " + "Freshman";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
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 month+"/"+day+"/"+year;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
public class Employee extends Person {
// Declaring variables
private String office;
private double salary;
private MyDate dateHired;
// Zero Argument Constructor
public Employee() {
super();
}
// Parameterized constructor.
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;
}
// Setters and getters
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;
}
// toString() method displays the contents of the object.
@Override
public String toString() {
return super.toString() + " office=" + office + ", salary=" + salary;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
public class Faculty extends Employee {
// Declaring variables
private int office_hours;
// Zero Argument Constructor
public Faculty() {
super();
}
// Parameterized constructor.
public Faculty(String name, String address,String phoneNo,String email, String office, double salary,MyDate datehired,
int office_hours) {
super(name, address,phoneNo,email, office, salary,datehired);
this.office_hours = office_hours;
}
// Setters and getters
public int getOffice_hours() {
return office_hours;
}
public void setOffice_hours(int office_hours) {
this.office_hours = office_hours;
}
// toString() method displays the contents of the object.
@Override
public String toString() {
return super.toString() + " office_hours=" + office_hours;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package personmain;
/**
*
* @author Home
*/
public class Staff extends Employee {
// Declaring variables
private String title;
// Zero Argument Constructor
public Staff() {
super();
}
// Parameterized constructor.
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;
}
// Setters and getters
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
// toString() method displays the contents of the object.
@Override
public String toString() {
return super.toString() + " Title=" + title;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started