Question: JAVA For the Person class, create two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name. A
JAVA
For the Person class, create two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name. A student has a class status varibale of type int with possible 4 status options (1 = FRESHMAN, 2 = SOPHOMORE, 3 = JUNIOR, or 4 = SENIOR). An employee has a salary (int) A faculty member has a rank (int). A staff member has a title (string). All classes need to have parameterized/custome constructors to set all the variables. Override the toString method in each class to display the class name and the instance name attribute. (same as Person class) The test program will create an instance of one of these classes and invokes their toString() methods. Sample Input for person instance 1 David Sample Output for person instance Person name is David Sample Input for student instance 2 Danial 3 Sample Output for student instance Student name is Danial and status is JUNIOR Sample Input for employee instance 3 Emma 200 Sample Output for employee instance Employee name is Emma and salary is 200 Sample Input for faculty instance 4 Emily 100 5
DRIVER JAVA
import java.util.*; public class Driver { public static void main(String[] args){ Person p = null; int which; String name; int status = 0; int salary = 0; int rank = 0; String title = "0"; Scanner input = new Scanner(System.in); which = input.nextInt(); name = input.next(); switch (which) { case 1 : p = new Person(name); break; case 2 : status = input.nextInt(); p = new Student(name, status); break; case 3 : salary = input.nextInt(); p = new Employee(name, salary); break; case 4 : salary = input.nextInt(); rank = input.nextInt(); p = new Faculty(name, salary, rank); break; case 5 : salary = input.nextInt(); title = input.next(); p = new Staff(name, salary, title); break; } System.out.println(p.toString()); } }
SOLUTION JAVA
import java.util.*; import java.lang.*; import java.io.*; // all the classes in this Solution.java file have to be default visibilty. // Do NOT change the visibilty to public. // DO not change anything in the Person class Please. class Person{ private String name; public Person(String name){ this.name = name; } @Override public String toString() { return this.getClass().getName() + " name is " + this.name; } } // Please write your code here //PLEASE WRITE YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
