Create a class named Employee. The class should store the following information.
ID: 3761652 • Letter: C
Question
Create a class named Employee. The class should store the following information. first name last name employee number Create a class named HourlyEmployee that inherits from the Employee class. This class should store the following additional pieces of information: shift ( "days" OR "swings" OR "mids" ) hourly rate Create a class named SalaryEmployee that inherits from the Employee class. This class should store the following additional information: Yearly salary For all three of the classes: all fields should be declared to have private access all fields should have accessor ( get ) and mutator ( set ) methods there should be a single constructor that requires values for ALL of the fields in the class ( and for its superclass ) there should be a toString method that displays a formatted mini report including ALL of the fields of the class ( including any in the superclass ) Create a test class called TestEmployeeClasses Create 1 object of each class: Employee, HourlyEmployee, and SalaryEmployee Prompt the user of your program ( AFTER displaying a description of your program first… ) to enter in the information required to create the 3 objects. Test all of the get/set methods for all of the objects. For each of the objects display a report ( using the toString method for the object )
Explanation / Answer
// PolymorphismTest.java
public class PolymorphismTest
{
public static void main( String args[])
{
CommissionEmployee3 commissionEmployee = new CommissionEmployee3
("Sue", "Jones", "222-22-2222", 10000, .06 );
BasePlusCommissionEmployee4 basePlusCommissionEmployee =new BasePlusCommissionEmployee4("Bob", "Lewis", "333-33-3333", 5000, .04,300 );
System.out.printf( "%s %s: %s ", "Call CommissionEmployee3's toString with superclass reference ", "to superclass object", commissionEmployee.toString());
System.out.printf( "%s %s: %s ","Call BasePlusCommissionEmployee4's toString with subclass","reference to subclass object",
basePlusCommissionEmployee.toString() );
CommissionEmployee3 commissionEmployee2 =basePlusCommissionEmployee;
System.out.printf( "%s %s: %s ","Call BasePlusCommissionEmployee4's toString with superclass","reference to subclass object", commissionEmployee2.toString() );
} }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.