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.
*Driver class*
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 file*
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
// Have to create own classes in solution file where it says plese write your code here
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