Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. A. Design the logic for a company application that breaks down payroll by dep

ID: 3539318 • Letter: A

Question

a.      A. Design the logic for a company application that breaks down payroll by department. Input includes each employee%u2019s last name, first name, department number, hourly salary, and number of hours worked. The output is a list of the seven departments in the company (numbered 1 through 7) and the total gross payroll (rate times hours) for each department.

b.      B. Modify Exercise 7a so that the report lists department names as well as numbers. The department names are shown in the table on page 170.



Explanation / Answer

package inherit1;

public abstract class Employee
{

// 1) make the instance variables name of type String and hireDate of type Date

protected String name;
private Date hireDate;

// 2) make a no-argument constructor and set name to "no name" and hireDate to 1,1,1000 (a place holder)

public Employee(){
  name = "no name yet";
  hireDate = new Date(1,1,1000);
}

// 3) make a constructor to set the name and the hireDate
public Employee ( String n, Date hd){
  name=n;
  hireDate=hd;
}

// 4) make a copy constructor
public Employee ( Employee o ){
  name = o.name;
  hireDate = o.hireDate;
}

// 5) make a getter for the name


public String getName(){
  printSomething();
  return name;
}

private void printSomething(){
  System.out.println( "you asked for my name!");
}

// 6) make a getter for the hireDate
public Date getHireDate(){
  return hireDate;
}

// 7) make a setter for the name
public void setName(String n){
  name=n;
}

// 8) make a setter for the hireDate
public void setHireDate(Date hd){
  hireDate = hd ;
}

// 9) make a toString method name:xxxx hired:xxxxxx
public String toString(){
  
  return "name: " + name + " hired: " + hireDate;
}

// 10) make an equals method, equal if name is the same and hireDate is the same
/*public boolean equals(Employee o){
  return name.equals( o.name ) && hireDate.equals(o.hireDate);
}
*/

public void callAnnounce(){
  announce();
}

public static void announce(){
  
  System.out.println("This is the Employee Class");
}

public boolean equals( Object o){
  if( o == null)
   return false;
  if( getClass() != o.getClass() )
   return false;
  
  Employee oE = (Employee) o ;
  
  
  return name.equals( oE.name ) && hireDate.equals( oE.hireDate) &&
    getPay()==oE.getPay();
}


public abstract double getPay( );


}


// 1) make an HourlyEmployee from the Employee parent class
public class HourlyEmployee extends Employee
{

// 2) make private instance variables wageRate of type doulbe and hours of type double
private double wageRate;
private double hours;



// 3) make a no argument constructor to set the wageRate to 0 and the hours to zero (remember to call super)

public HourlyEmployee (){
  
  /*
   this( "no name yet", new Date(1,1,1000), 0, 0 );
  */
  super();


  
  wageRate=0;
  hours = 0;
  
}


// 4) make a constructor to set the name, hirdate, wageRate and hours
public HourlyEmployee(String n, Date hd, double w, double h ){
  super(n , hd );
  wageRate=w;
  hours=h;
}


// 5) make a copy constructor
public HourlyEmployee( HourlyEmployee o ){
  super( o );
  //or this way =>super( o.getName(), o.getHireDate() );  
  wageRate = o.wageRate;
  hours = o.hours;
}

// 6) make a getter for the rate
public double getWageRate(){
  return wageRate;
}


// 7) make a method called getPay that calculates the salary


// 8) make a setter for the hours - only change it if its positive
    public void setHours( double h ){
    if( h > 0)
      hours = h;
    }
   

// 9) make a setter for the rate - only change it if its positive
    public void setWageRate( double w ){
    if(w>0)
      wageRate=w;
    }

public static void announce(){
  
  System.out.println("This is the HourlyEmployee Class");
}
public void callAnnounce(){
  announce();
}

   
// 10) make a toString method name:xxxx hired:xxxxxx
//          wage: xxx per hour for xxxx hours
public String toString(){
  
  return super.toString() + // or "name: " + getName() + " hired: " + getHiredDate +
   " wage: " + wageRate + " per hour for " + hours + " hours";
  
  
  
  
}

// 11) make an equals method - name is same, hireDate same, wageRate is the same and hours is the same

public boolean equals( HourlyEmployee o ) {
  o.hours = 0;
  return super.equals(o) && wageRate==o.wageRate && hours==o.hours;
  
}

public double getPay(){
  return wageRate*hours;
}




}


// 1) make class SalariedEmployee from parent class Employee
public class SalariedEmployee extends Employee
{

// 2) make salary double instance variable (annual salary)
private double salary ;

// 3) make a no-argument constructor
public static void announce(){
  
  System.out.println("This is the Salaried Employee Class");
}
public void callAnnounce(){
  announce();
}


public SalariedEmployee( ){
// super();
  super("no name", null);
  salary=0;
  
  
}

// 4) make a constructor to set name, hireDate, and salary - only set salary if its >0;
public SalariedEmployee(String n, Date hd, double s ) {
  super(n , hd);
  if(s>0)
   salary = s;
}

// 5) make a copy constructor
public SalariedEmployee( SalariedEmployee o){
  super( o );
  salary = o.salary;
}

// 6) make a getter for salary
public double getSalary(){
  return salary;
}

// 7) make a method called getPay that returns void to calculate the monthly salary
public double getPay(){
  return salary/12;
}

// 8) make a setter for salary - only if its >0 change it
public void setSalary( double s ){
  if( s> 0)
   salary = s;
}

// 9) make a toString - name:xxxx hired:xxxxxx
//       xxxxxx salary per year
public String toString(){
  return super.toString() + " " + salary + " salary per year" ;
}

// 10) make an equals method - same name, hireDate and salary

public boolean equals( SalariedEmployee o ){
  
  return super.equals(o) && salary == o.salary ;
  
}
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote