This is heavily based on Programming Exercise 11.2 in the Liang text. However, y
ID: 3852862 • Letter: T
Question
This is heavily based on Programming Exercise 11.2 in the Liang text. However, you will not need the text version to do this assignment, many changes have been made.
The archive assign02.zip is attached has a skeleton project for this assignment. All the test programs are there that will be used to test your work. The different classes you are to implement are present in skeleton form.
Requirements
Implement classes Person, Student, Employee, Faculty and Staff. These represent the people and categories of people you might find at a college or university. These are related by inheritance as follows
Employee and Student both extend Person
Faculty and Staff both extend Employee
Here are the instance fields of each class:
Class
Instance Fields
Person
name
email address
Employee
salary
date hiredB
Faculty
office hours
Staff
title
Student
class statusA
Here are the notes from the table:
This should be a string. The most common values will be one of “FR”, “SO”, “JR”, “SE”, but don’t bother testing for that.
Use the standard Java Date class
Instance field types should be String except for salary and date hired.
The classes will have the following methods:
Getters and setters for all instance fields, except
Date hired has no setter
A single constructor in each class that initializes all the fields for that class both inherited and defined in the class itself, except for date hired For example, he Staff constructor will have 4 parameters: title, salary, name, and email address
The constructor for Employee will initialize the hire date to the current date
Override toString in each class to print the name of the class followed by the name of the person, separated by a colon. For example, if Bob is a staff member, his object would print as Staff:Bob.
format each program start like this for each role student-etc.
package assign02;
import java.util.Date;
public class Employee {
}
Class
Instance Fields
Person
name
email address
Employee
salary
date hiredB
Faculty
office hours
Staff
title
Student
class statusA
Explanation / Answer
import java.util.Date;
public class PersonStudentEmployee
{
public static void main(String[] args)
{
Person myPerson = new Person();
System.out.println(myPerson.toString());
Student myStudent = new Student();
System.out.println(myStudent.toString());
Employee myEmployee = new Employee();
System.out.println(myEmployee.toString());
Faculty myFaculty = new Faculty();
System.out.println(myFaculty.toString());
Staff myStaff = new Staff();
System.out.println(myStaff.toString());
}
}
class Person
{
//define var1, var2, var3, var4
String name;
String address;
String phoneNumber;
String email;
//no arg constructer
Person()
{
name = "mark hill";
address = "main street.";
phoneNumber = "(123)-465-8540";
email = "123@outlook.com";
}
//define method toString()
public String toString()
{
return super.toString() + "Person" + name;
}
}
class Student extends Person
{
//define class status
public static final int FRESHMEN = 1;
public static final int SOPHOMORE = 2;
public static final int JUNIOR = 3;
public static final int SENIOR = 4;
int classStatus;
//no arg constructer
Student()
{
classStatus = FRESHMEN;
}
//define method toString()
public String toString()
{
return super.toString() + "Student" + name;
}
}
class Employee extends Person
{
//define var1, var2, var 3
String office;
String salary;
Date dateHired = new java.util.Date();
//no arg constructer
Employee()
{
office = "584";
salary = "$10,000";
}
//define method toString()
public String toString()
{
return super.toString() + "Employee" + name;
}
}
class Faculty extends Employee
{
//define var1, var2
String officeHours;
String rank;
//no arg constructer
Faculty()
{
officeHours = "7-10 am";
rank = "Professor";
}
//define method toString()
public String toString()
{
return super.tostring() + "Faculty" + name;
}
}
class Staff extends Employee
{
//define var1
String title;
//no arg constructer
Staff()
{
title = "Janitor";
}
//define method toString()
public String toString()
{
return super.toString() + "Staff" + name;
}
}
class MyDate
{
//define var1, var2, var 3
int year;
int month;
int day;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.