Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA NEED HELP QUICK For this Programming Project, start with implementations of the Person, Student, Graduate and Undergraduate classes as depicted in Figure 8.4 and

JAVA NEED HELP QUICK

For this Programming Project, start with implementations of the Person, Student, Graduate and Undergraduate classes as depicted in Figure 8.4 and the polymorphism demo in Listing 8.6. Define the Employee, Faculty, and Staff classes as depicted in Figure 8.2. The Employee class should have instance variables to store the employee ID as an int and the employees department as a String. The Faculty class should have an instance variable to store the faculty members title (e.g. "Professor of Computer Science") as a String. The Staff class should have an instance variable to store the staff members pay grade (a number from 1 to 20) as an int. Every class should have appropriate constructors, accessors, and mutators, along with a writeOutput method that outputs all of the instance variable values.

Modify the program in Listing 8.6 to include at least one Faculty object and at least one Staff object in addition to the Undergraduate and Student objects. You should output the name, employee ID, department, and title for the Faculty objects, and the name, employee ID, department, and pay grade for the Staff objects.

HERES MY CODE SO FAR

package projectfinal;

public class ProjectFinal

{

public static void main(String[] args)

{

Person[] people = new Person[5];

people[0] = new Undergraduate("Cotton manny",4910,1);

people[1] = new Faculty(999, "Bond", "Computer Science", "Professor of Computer Science");

people[2] = new Faculty(777,"Pond", "Computer Science", "Asst.Profressor of Computer Science" );

people[3] = new Staff(799,"Gosling", "Computer Science", 15);

people[4] = new Staff(899, "Bill", "Computer Science",15);

for(Person p:people)

{

if(p instanceof Faculty|| p instanceof Staff)

p.writeOutput();

System.out.println();

}

//end of

}

}

package projectfinal;

/**

*

* @author derrickprophet

*/

public class Person

{

private String name;

public Person()

{

name = "No name yet";

}

public Person (String initialName)

{

name = initialName;

}

public void setName(String newName)

{

name = newName;

}

public String getName()

{

return name;

}

public void writeOutput()

{

System.out.println("Name:"+name);

}

}

public class Employee extends Person

{

private int empId;

private String empDepartment;

public Employee()

{

super();

empId=0;

empDepartment ="Not set";

}

public Employee(int empId,String empName,String empDepartment)

{

super(empName);

setEmpid(empId);

setEmpDept(empDepartment);

}

private void setEmpid(int empId)

{

this.empId =empId;

}

private void setEmpDept(String empDepartment)

{

this.empDepartment =empDepartment;

}

private int getEmpid()

{

return empId;

}

private String getEmpDept()

{

return empDepartment;

}

/**

*

*/

@Override

public void writeOutput()

{

System.out.println("Emploee ID:"+empId);

super.writeOutput();

System.out.println("Employee Department:"+empDepartment);

}

@Override

public String toString()

{

reutrn "Employee name:"+ getName()+

" Employee ID:" + getEmpid()+

" Employee Department :" + getEmpDept();

return null;

}

private String getName() {

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

}

}

package projectfinal;

/**

*

* @author derrickprophet

*/

public class Faculty extends Employee

{

private String facTitle;

public Faculty()

{

super();

facTitle ="not set";

}

public Faculty(int empId, String empName, String empDepartment, String facTitle)

{

super(empId,empName,empDepartment);

setTitle(facTitle);

}

public void setTitle(String facTitle)

{

this.facTitle=factTitle;

}

public String getTitle()

{

return facTitle;

}

public void writeOutput()

{

super.writeOutput()

System.out.println("Employee Title"+factTitle);

}

public String toString()

{

return super.toString()+" Employee Title:"+getTitle();

}

}

package projectfinal;

/**

*

* @author derrickprophet

*/

public class Staff extends Employee

{

private int paygrade;

public Staff()

{

super();

}

public Staff(int empId, String empName, String empDepartment, int paygrade)

{

super(empId,empName,empDepartment);

setGrade(paygrade);

}

public void setGrade(int paygrade)

{

if((paygrade>=1) && (paygrade<=20))

this.paygrade=paygrade;

else

System.out.println("illegal paygrade");

}

public int getGrade()

{

return paygrade;

}

public void writeOutput()

{

super.writeOutput();

System.out.println("Employee Grade"+paygrade);

}

public String toString()

{

return super.toString()+" Employee Grade"+getGrade();

}

}

package projectfinal;

/**

*

* @author derrickprophet

*/

public class Student extends Person

{

private int studentNumber;

public Student()

{

super();

studentNumber =0;

}

public Student (String initialName, int initialStudentNumber)

{

super(initialName);

setStudentNumber(initialStudentNumber);

}

public void setStudentNumber(int newStudentNumber)

{

studentNumber = newStudentNumber;

}

public int getStudentNumber()

{

return studentNumber;

}

public void writeOutput()

{

System.out.println("name"+getName());

System.out.println("Student Number:"+studentNumber);

}

Public StringtoString()

{

return "Name"+getName()+" Student number:"+ studentNumber;

}

}

package projectfinal;

/**

*

* @author derrickprophet

*/

public class Undergraduate extends Student

{

private int level;

public Undergraduate()

{

super();

level = 1;

}

public Undergraduate(String initialName, int initialStudentNumber, int initialLevel)

{

super(initialName, initialStudentNumber);

setLevel(initialLevel);

}

public void setLevel(int newLevel)

{

if((1<=newLevel) && (newLevel<=4))

level = newLevel;

else

{

System.out.println("Illegal level!");

System.exit(0);

}

}

public int getLevel()

{

return level;

}

public void writeOutput()

{

super.writeOutput();

System.out.println("Student Level:"+level);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

how to output " / \ _ / \ " in java

Answered: 1 week ago