Question
Plz give the right code in Java and it match with the output below. Don't just give me what i already have from figures. I
Plz give the right code in Java and it match with the output below. Don't just give me what i already have from figures. I need your output too.
For this Programming Project, start with implementations of the Person, Student, 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. Without modification to the for loop, the report 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.
Note:
1. The solution must use the class Employee2, to distinguish it from the Employee class from Practice Program 1.
2. The project must have the following classes:
a. person, in file person.java
b. student, in student.java
c. underGraduate, in underGraduate.java
d. employee2, in file employee2.java
e. faculty, in file faculty.java
f. staff, in staff.java
g. polymorphismDemo, in a file polymorphismDemo.java
Figure 8.2 |
public class Student extends Person { private int studentNumber; public Student () { super (); studentNumber = 0; //Indicating no number yet } public Student (String initialName, int initialStudentNumber) { super (initialName); studentNumber = initialStudentNumber; } public void reset (String newName, int newStudentNumber) { setName (newName); studentNumber = newStudentNumber; } public int getStudentNumber () { return studentNumber; } public void setStudentNumber (int newStudentNumber) { studentNumber = newStudentNumber; } public void writeOutput () { System.out.println ("Name: " + getName ()); System.out.println ("Student Number: " + studentNumber); } public boolean equals (Student otherStudent) { return this.hasSameName (otherStudent) && (this.studentNumber == otherStudent.studentNumber); } } |
Figure 8.4 |
public class Undergraduate extends Student { private int level; //1 for freshman, 2 for sophomore, //3 for junior, or 4 for senior. public Undergraduate () { super (); level = 1; } public Undergraduate (String initialName, int initialStudentNumber, int initialLevel) { super (initialName, initialStudentNumber); setLevel (initialLevel); //Checks 1 <= initialLevel <= 4 } public void reset (String newName, int newStudentNumber, int newLevel) { reset (newName, newStudentNumber); //Students reset setLevel (newLevel); //Checks 1 <= newLevel <= 4 } public int getLevel () { return level; } public void setLevel (int newLevel) { if ((1 <= newLevel) && (newLevel <= 4)) level = newLevel; else { System.out.println ("Illegal level!"); System.exit (0); } } public void writeOutput () { super.writeOutput (); System.out.println ("Student Level: " + level); } public boolean equals (Undergraduate otherUndergraduate) { return equals ((Student) otherUndergraduate) && (this.level == otherUndergraduate.level); } } |
Figure 8.6 |
public class PolymorphismDemo { public static void main(String[] args) { Person[] people = new Person[4]; people[0] = new Undergraduate("Cotty, Manny", 4910, 1); people[1] = new Undergraduate("Kick, Anita", 9931, 2); people[2] = new Student("DeBanque, Robin", 8812); people[3] = new Undergraduate("Bugg, June", 9901, 4); for (Person p : people) { p.writeOutput(); System.out.println(); } } } |
Sample output:
----jGRASP exec: java PolymorphismDemo Name: Cotty, Manny Student Number: 4910 Student Level: 1 Name: Kick, Anita Student Number: 9931 Student Level: 2 Name: DeBanque, Robin Student Number: 8812 Name: Bugg, June Student Number: 9901 Student Level: 4 Name: Mock, Kenrick Dept: Computer Science Employee ID: 3056 Title: Professor of Computer Science Name: Jones, James Dept: Mathematical Sciences Employee ID: 1551 Pay Grade: 15 ----jGRASP: operation complete
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