Question

In: Computer Science

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.

Implement the classes, and write a test program that creates a salaried employee and two hourly employees. One of the hourly employees should have hours worked set to less than 40 and one should have hours worked set to more than 40. The test program should display all attributes for the three employees. To keep things simple, the employee classes don’t need to do any editing.

Previous Code:

EmployeeInfo.java

public class Employeeinfo {
  
public static void main(String[] args) {
   int n_emp;   
   Scanner scanner = new Scanner(System.in);
   System.out.println("Enter Number of Employee(s)");
   n_emp = scanner.nextInt();
   Employee array[]=new Employee[n_emp];
   int i = 0;
   while(i<n_emp)
       {
           String s1,s2,s3; //* String for Input
           System.out.println("What is Employees First Name?");
           s1 = scanner.next();
           System.out.println("What is Employees Last Name?");
           s2 = scanner.next();
           Name n = new Name(s1, s2);
           int i1,i2,i3;
           while(true)
               {
                       System.out.println("Please Enter Year Hired:");
                       i1 = scanner.nextInt();
                       if(i1 >= 1900 && i1 <= 2020)
                   {
                       break;
                   }
                       else
                       {
                       System.out.println("Sorry not within Range, Please enter a yearly range between 1900 - 2020"); //* Error if not in range
                       }
               }
           while(true)
           {
                   System.out.println("Please Enter Month Hired:");
                   i2 = scanner.nextInt();
                   if(i2 >= 1 && i2 <= 12)
               {
                   break;
               }
                   else
                   {
                   System.out.println("Sorry not within Range, Please enter a monthly range between 1 - 12");
               }
           }
           while(true)
               {
                   System.out.println("Please Enter Day Hired:");
                   i3 = scanner.nextInt();
                   if(i3 >= 1 && i3 <= 31)
                   {
                       break;
                   }
                   else
                   {
                   System.out.println("Sorry not within Range, Please enter a daily range between 1 - 31");
                   }
               }

           Date d = new Date(i3,i2,i1);

                   System.out.println("Please Enter Street Name:");
                   s1 = scanner.next();

                   System.out.println("Please Enter City");
                   s2 = scanner.next();

                   System.out.println("Please Enter State");
                   s3 = scanner.next();   

                   System.out.println("Please Enter ZipCode");
                   i3 = scanner.nextInt();

                   Address a = new Address(s1, s2, s3, i3);   

                   System.out.println("Please enter a Employee Number");
                   i1 = scanner.nextInt();
                   Employee e =new Employee(i1,n,d,a);

e.myname.fname = n.fname; //* Array to display
e.myname.lname = n.lname;
e.mydate.month = d.month;
e.mydate.day = d.day;
e.mydate.year = d.year;
e.myadress.street = a.street;
e.myadress.state = a.state;
e.myadress.city = a.city;
e.myadress.zipcode = a.zipcode;
array[i] = e;
i++;
       }  
                   System.out.println("List of Employee(s): "); //Print List
                   for (i = 0 ; i< n_emp; i++)
                   {
                   System.out.println( array[i].number + " "+ array[i].myname.fname + " " + array[i].myname.lname + " | " + array[i].mydate.month + "/" + array[i].mydate.day + "/" + array[i].mydate.year + " | "+ array[i].myadress.street + " "+ array[i].myadress.state + " "+ array[i].myadress.city + ","+ array[i].myadress.zipcode);   
                   }
   }
}

Date.Java

public class Date {
   public int month;
   public int day;
   public int year;

   public Date(int month, int day, int year) {
   this.month = month;
   this.day = day;
   this.year = year;
   }
   public Date() {
   this.month = 0;
   this.day = 0;
   this.year = 0;

   }
}

Employee.java

public class Employee {
   public int number;
   public Date mydate;
   public Address myadress;
   public Name myname;

   public Employee(int number, Name myname, Date mydate, Address myadress) {
   this.number = number;
   this.mydate = new Date();
   this.myadress = new Address();
   this.myname = new Name();
   }
   public Employee() {
   this.number = number;
   this.mydate = new Date();
   this.myadress = new Address();
   this.myname = new Name();
   }
}

Name.Java

public class Name {
   public String fname;
   public String lname;

   public Name(String fname, String lname) {
   this.fname = fname;
   this.lname = lname;
   }
   public Name() {
   this.fname = "";
   this.lname = "";
   }
}

Address.Java

public class Address {
   public String street ;
   public String state ;
   public String city;
   public int zipcode;

   public Address(String street, String state, String city, int zipcode) {
   this.street = street;
   this.state = state;
   this.city = city;
   this.zipcode = zipcode;
   }
   public Address() {
   this.street = "";
   this.state = "";
   this.city = "";
   this.zipcode = 0;
   }
}

Solutions

Expert Solution

// Date.java

public class Date {
  
   public int month;
   public int day;
   public int year;

   public Date(int month, int day, int year) {
   this.month = month;
   this.day = day;
   this.year = year;
   }
  
   public Date() {
   this.month = 0;
   this.day = 0;
   this.year = 0;
   }
}

//end of Date.java

// Name.java

public class Name {
  
   public String fname;
   public String lname;

   public Name(String fname, String lname) {
   this.fname = fname;
   this.lname = lname;
   }
  
   public Name() {
   this.fname = "";
   this.lname = "";
   }
}

//end of Name.java

// Address.java

public class Address {
  
   public String street ;
   public String state ;
   public String city;
   public int zipcode;

   public Address(String street, String state, String city, int zipcode) {
   this.street = street;
   this.state = state;
   this.city = city;
   this.zipcode = zipcode;
   }
  
   public Address() {
   this.street = "";
   this.state = "";
   this.city = "";
   this.zipcode = 0;
   }
}

//end of Address.java

// Employee.java

public class Employee {
  
   public int number;
   public Date mydate;
   public Address myadress;
   public Name myname;

   public Employee(int number, Name myname, Date mydate, Address myadress) {
   this.number = number;
   this.mydate = mydate;
   this.myadress = myadress;
   this.myname = myname;
   }
  
   public Employee() {
   this.number = 0;
   this.mydate = new Date();
   this.myadress = new Address();
   this.myname = new Name();
   }
  
   // method to display the details of the Employee
   public void display()
   {
       System.out.println("Number: "+number);
       System.out.println("Name: "+myname.fname+" "+myname.lname);
       System.out.println("Data: "+mydate.month+"/"+mydate.day+"/"+mydate.year);
       System.out.println("Address: "+myadress.street+" "+myadress.city+", "+myadress.state+", "+myadress.zipcode);
   }
}
// end of Employee.java

// SalariedEmployee.java

public class SalariedEmployee extends Employee
{
   public double salary;
  
   // parameterized constructor
   public SalariedEmployee(int number, Name myname, Date mydate, Address myadress, double salary)
   {
       super(number, myname, mydate, myadress); // call Employee's constructor
       this.salary = salary;
   }
  
   // default constructor
   public SalariedEmployee()
   {
       super();
       this.salary = 0;
   }
  
   // override Employee's display method to display the additional details
   public void display()
   {
       super.display();
       System.out.printf("Salary: $%,.2f\n",salary);
   }
}
//end of SalariedEmployee.java

// HourlyEmployee.java

public class HourlyEmployee extends Employee
{
   public double pay_rate;
   public int hours_worked;
   public double earnings;
  
   // parameterized constructor
   public HourlyEmployee(int number, Name myname, Date mydate, Address myadress, double pay_rate, int hours_worked)
   {
       super(number, myname, mydate, myadress);
       this.pay_rate = pay_rate;
       this.hours_worked = hours_worked;
       // calculate earnings
       if(hours_worked <= 40) // no overtime
           earnings = this.pay_rate*this.hours_worked;
       else // overtime
           earnings = this.pay_rate*40 + (this.hours_worked-40)*1.5*this.pay_rate;
   }
  
   // default constructor
   public HourlyEmployee()
   {
       super();
       pay_rate = 0;
       hours_worked = 0;
       earnings = 0;
   }
  
   // override display method
   public void display()
   {
       super.display();
       System.out.printf("Pay rate: $%,.2f\n",pay_rate);
       System.out.println("Hours Worked: "+hours_worked);
       System.out.printf("Earnings: $%,.2f\n",earnings);
   }
}
//end of HourlyEmployee.java

// Employeeinfo.java

public class Employeeinfo {
  
   public static void main(String[] args)
   {
       // create SalariedEmployee
       SalariedEmployee s = new SalariedEmployee(12, new Name("Shaun","Marsh"), new Date(11, 7, 1995), new Address("Street1","State1","City1",70081), 75000);

       // create HourlyEmployee without any overtime
       HourlyEmployee h1 = new HourlyEmployee(15, new Name("Harry","Doe"), new Date(7, 16, 2000), new Address("Street2","State2","City2",60181), 45.75, 35);

       // create HourlyEmployee with overtime
       HourlyEmployee h2 = new HourlyEmployee(25, new Name("Jerry","Hope"), new Date(10, 16, 2007), new Address("Street3","State3","City3",80111), 45.75, 45);
      
       // display the details
       s.display();
       System.out.println();
       h1.display();
       System.out.println();
       h2.display();
   }

}


//end of Employeeinfo.java

Output:


Related Solutions

**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design...
**JAVA LANGUAGE** This assignment will use the Employee class that you developed for assignment 6. Design two sub- classes of Employee...FullTimeEmployee and HourlyEmployee. A full-time employee has an annual salary attribute and may elect to receive life insurance. An hourly employee has an hourly pay rate attribute, an hours worked attribute for the current pay period, a total hours worked attribute for the current year, a current earnings attribute (for current pay period), a cumulative earnings attribute (for the current...
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...
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...
Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.
  Part I:   The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class. * Update the function display() to be a virtual function     * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects. Part II: The Derived Classes Add an weeklyEarning() function to each...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee Hierarchy that you created in Java in Programming Assignment 2 by adding an interface called Compensation with the following two methods: earnings() - receives no parameters and returns a double. raise(double percent) - receives one parameter which is the percentage of the raise and returns a void. Create the abstract class CompensationModel which implements the Compensation interface. Create the following classes as subclasses of...
Using UML, design a class that allows you to store and print employee information: name, id,...
Using UML, design a class that allows you to store and print employee information: name, id, and hourly_salary. Include the appropriate mutator and accessor methods. Write the code to create the class. Write a test program that instantiates an employee object. After the object is created write the code to give the employee a 3% raise. (IN PYTHON)
Q3) Design a class for saving data of employee, the class should have multiple constructors (constructor...
Q3) Design a class for saving data of employee, the class should have multiple constructors (constructor overloading) for initializing objects with different parameters. The employee class should have different functions for saving and updating bio-data, educational background, and current status like experience, Salary, position & travel history. The employee class should have a function which asks user what do he likes to see about employee (.i.e., Bio-data, current status....) and only show the respective data. Create two objects of interns...
Overview For this assignment, design and implement the methods for a class that can be used...
Overview For this assignment, design and implement the methods for a class that can be used to represent a quadratic equation. int main() has already been written for this assignment. It is available for download from Blackboard or by using the following link: http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm8.cpp All that needs to be done for this assignment is to add the class definition and method implementation to the above CPP file. The Quadratic class Data Members The class contains three data members: an integer...
This assignment will test your knowledge and skills in C++. Create a class named employee and...
This assignment will test your knowledge and skills in C++. Create a class named employee and have the data members of: Name ID Salary Create a class named manager that inherits the employee class and adds the data members: Managed_Employees (Array of up to 3 employees) Department Create methods to update each data member in the employee class. Create a method to print out the managed employees sorted by their salary in the manager class. (You can use one of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT