Question

In: Computer Science

Design a class named Person and its two subclasses named Student and Employee. Make Faculty and...

Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.

Write a test program that creates objects of Person, Student, Employee, Faculty, and Staff, and invoke their toString() methods.                  

Solutions

Expert Solution

class Person
{
   String name;
   String address;
   String phonenumber;
   String email;
   Person(String name, String address, String phonenumber, String email)
   {
       this.name = name;
       this.address = address;
       this.phonenumber = phonenumber;
       this.email = email;
   }
   public String toString()
   {
       System.out.println("class name: Person");
       System.out.println("Details");
       return "name:\t"+this.name+"\naddress:\t"+this.address+"\nphone number:\t"+this.phonenumber+"\nemail:\t"+this.email;
   }
}
class Student extends Person
{
   final String status;
   Student(String name, String address, String phonenumber, String email, String status)
   {
       super(name, address, phonenumber, email);
       this.status = status;
   }
   public String toString()
   {
       System.out.println("class name: Student");
       System.out.println("Details");
       return "name:\t"+this.name+"\naddress:\t"+this.address+"\nphone number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\nstatus:\t"+this.status;
   }
}
class Employee extends Person
{
   String office;
   double salary;
   String date;
   Employee(String name, String address, String phonenumber, String email, String office, double salary, String date)
   {
       super(name, address, phonenumber, email);
       this.office = office;
       this.salary = salary;
       this.date = date;
   }
   public String toString()
   {
       System.out.println("class name: Employee");
       System.out.println("Details");
       return "name:\t"+this.name+"\naddress:\t"+this.address+"\nphone number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\noffice:\t"+this.office+"\nsalary:\t"+this.salary+"\ndate:\t"+this.date;
   }
  
}
class Faculty extends Employee
{
   int officehours;
   int rank;
   Faculty(String name, String address, String phonenumber, String email, String office, double salary, String date, int officehours, int rank)
   {
       super(name, address, phonenumber, email, office, salary, date);
       this.officehours = officehours;
       this.rank = rank;
   }
   public String toString()
   {
       System.out.println("class name: Faculty");
       System.out.println("Details");
       return "name:\t"+this.name+"\naddress:\t"+this.address+"\nphone number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\noffice hours:\t"+this.officehours+"\nrank\t"+this.rank;
   }
  
}
class Staff extends Employee
{
   String title;
   Staff(String name, String address, String phonenumber, String email, String office, double salary, String date, String title)
   {
       super(name, address, phonenumber, email, office, salary, date);
       this.title = title;
   }
   public String toString()
   {
       System.out.println("class name: Staff");
       System.out.println("Details");
       return "name:\t"+this.name+"\naddress:\t"+this.address+"\nphone number:\t"+this.phonenumber+"\nemail:\t"+this.email+"\ntitle:\t"+this.title;
   }
}
public class Test
{
   public static void main(String args[])
   {
       Person person1 = new Person("person1", "address1","5566777544","person1email");
       System.out.println(person1.toString());
       Person student1 = new Student("student1", "address2","55667897544","student1@gm.com", "junior");
       System.out.println(student1.toString());
       Person employee1 = new Employee("employee1", "address3","5578667544","employee1email", "banglore", 100000,"01-08-1019");
       System.out.println(employee1.toString());
       Person faculty1 = new Faculty("faculty1", "address4","6977987544","faculty1email", "banglore", 500000, "01-06-2018", 5, 3);
       System.out.println(faculty1.toString());
       Person staff1 = new Staff("staff1", "address5","75869695984","staff1email", "banglore", 500000, "01-06-2018", "title1");
       System.out.println(staff1.toString());
      
   }
}

If you have any doubts please comment and please don't dislike.


Related Solutions

Java Question Design a class named Person and its two subclasses named Student and Employee. Make...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A...
JAVA Design a class named Person and its two derived classes named Student and Employee. Make...
JAVA Design a class named Person and its two derived classes named Student and Employee. Make Faculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and datehired. Define a class named MyDate that contains the fields year, month, and day. A faculty member has office hours and a rank. A staff member has a...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary....
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
Design and develop a class named Person in Python that contains two data attributes that stores...
Design and develop a class named Person in Python that contains two data attributes that stores the first name and last name of a person and appropriate accessor and mutator methods. Implement a method named __repr__ that outputs the details of a person. Then Design and develop a class named Student that is derived from Person, the __init__ for which should receive first name and last name from the class Person and also assigns values to student id, course, and...
Design a class named Location for locating a maximal value and its location in a two-dimensional...
Design a class named Location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column and maxValue that stores the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two dimensional array: public static location locate Largest(double[][] a) The return value is an...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
In C# thanks please, Design a class named Person with properties for holding a person’s name,...
In C# thanks please, Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount. All...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT