Question

In: Computer Science

java Write our Test Driver program that tests our Classes and Class Relationship How we calculate...

java

Write our Test Driver program that tests our Classes and Class Relationship

How we calculate Net Pay after calculating taxes and deductions taxes:

regNetPay = regPay - (regPay * STATE_TAX) - (regPay * FED_TAX) + (dependents * .03 * regPay )

overtimeNetPay = overtimePay - (overtimePay * STATE_TAX) - (overtimePay * FED_TAX) + (dependents * .02 * overtimePay )

Example printPayStub() output:

Employee: Ochoa
Employee ID: 1234
Hourly Pay: $25.00
Shift: Days
Dependents: 2
Hours Worked: 50
RegGrossPay: $1,000.00 OvertimeGrossPay: $375.00 TotalGrossPay: 1375.00
RegTaxes Deducted: $150.00 ($100.00 State $50.00 Federal )  
OvertimeTaxes Deducted: $56.25 ($37.50 State $18.75 Federal)            
TotalTaxesDeducted: $205.75 ($137.00 State $68.75 Federal)
Tax Deductions: $75.00 RegPay, $60.00 Overtime, $15.00 total deductions
NetRegPay:   $910.00      NetOvertimePay:  $333.75       TotalNetPay: $1,243.75
payday: FRIDAY

public class Worker {

// Member variables

private String name;

private String employeeId;

private boolean dayShift;

private double HourlyPay;
// The default constructor

public Worker() {

this.name = "";

this.employeeId = "";

this.dayShift = false;

this.HourlyPay = 0.0;

}
public Worker(String name, String employeeId, boolean dayShift, double hourlyPay) {

super();

this.name = name;

this.employeeId = employeeId;

this.dayShift = dayShift;

HourlyPay = hourlyPay;

}
public Worker(Worker w) {
this.name = w.name;

this.employeeId = w.employeeId;

this.dayShift = w.dayShift;

this.HourlyPay = w.HourlyPay;
}
// This method sets the name of the worker

public void setName(String n) {

this.name = n;

}
// This method sets the employee Id

public void setemployeeId(String i) {

this.employeeId = i;

}
// This method sets the day shift

public void setdayShift(boolean s) {

this.dayShift = s;

}
// This method sets the hourly pay

public void setHourlyPay(double p) {

this.HourlyPay = p;

}
// This method returns the name of the worker

public String getname() {

return this.name;

}
// This method returns the employee Id

public String getemployeeId() {

return this.employeeId;

}
// This method returns if the worker is in day shift

public boolean getdayShift() {

return this.dayShift;

}
// This method returns the hourly pay

public double getHourlyPay() {

return this.HourlyPay;

}
// This method calculates the overtime pay

public double calculateOvertimePay(int hours) {
return (hours - 40) * 1.5 * HourlyPay;

}
// This method calculates and returns regular pay

public double calculateRegPay(int hours) {

return HourlyPay * hours;

}
@Override

public String toString() {

return "Worker name=" + name + ", employeeId=" + employeeId + ", dayShift=" + dayShift + ", HourlyPay="

+ HourlyPay;

}
  

}
/**************************************Payroll.java******************************/


public class Payroll {
private Worker w;

private int dependents;

private static final double STATE_TAX = 0.10;

private static final double FED_TAX = 0.05;
public Payroll() {
this.w = new Worker();

this.dependents = 0;

}
public Payroll(String name, String id, double pay, boolean s, int d) {
this.w = new Worker(name, id, s, pay);

this.dependents = d;

}
public Payroll(Worker w, int dependents) {

super();

this.w = w;

this.dependents = dependents;

}
public Worker getW() {

return w;

}
public void setW(Worker w) {

this.w = w;

}
public int getDependents() {

return dependents;

}
public void setDependents(int dependents) {

this.dependents = dependents;

}
public double calculateStateTax(int hours) {
return (w.calculateRegPay(hours) + w.calculateOvertimePay(hours)) * STATE_TAX;

}
public double calculateFedTax(int hours) {
return (w.calculateRegPay(hours) + w.calculateOvertimePay(hours)) * FED_TAX;

}
public void PrintPayStub(int hours) {

double regPay, overPay;

if (hours <= 40) {

// get the regular pay

regPay = w.calculateRegPay(hours) - calculateStateTax(hours) - calculateFedTax(hours)

+ (dependents * .03 * w.calculateRegPay(hours));

overPay = 0;

} else {

// get the overtime pay

regPay = 40 * w.getHourlyPay() - calculateStateTax(hours) - calculateFedTax(hours);

overPay = w.calculateOvertimePay(hours) - calculateStateTax(hours) - calculateFedTax(hours);

}

// display the pay Stub

System.out.println("\nName: \t" + w.getname());

System.out.println("Employee ID: " + w.getemployeeId());

System.out.print("Shift: ");

if (w.getdayShift())

System.out.println("\t\t day");

else

System.out.println("\t\tnight");

System.out.printf("Hourly Pay: $ %7.2f", w.getHourlyPay());

System.out.printf("\nRegular Pay: $ %.2f", regPay);

System.out.printf("\nOvertime Pay: $ %4.2f", overPay);

System.out.printf("\nGross Pay: $ %8.2f\n", (regPay + overPay));

}

}

-----------------

import java.util.Scanner;
public class WorkerPayrollTest {
public static void main(String[] args) {
Worker[] workers = new Worker[5];

Payroll[] payrolls = new Payroll[5];
Scanner scan = new Scanner(System.in);
for (int i = 0; i < workers.length; i++) {
System.out.print("Enter worker name: ");

String name = scan.nextLine();

System.out.print("Enter id: ");

String id = scan.nextLine();

System.out.print("Hourly Pay: ");

double pay = scan.nextDouble();

scan.nextLine();

System.out.print("Is day shift: ");

boolean shift = scan.nextBoolean();

scan.nextLine();
workers[i] = new Worker(name, id, shift, pay);
}

  

for (int i = 0; i < payrolls.length; i++) {

  

System.out.println(workers[i].toString());

System.out.print("Enter dependent: ");

int dependents = scan.nextInt();

scan.nextLine();

  

payrolls[i] = new Payroll(workers[i], dependents);

}

  

  

for (int i = 0; i < payrolls.length; i++) {

  

System.out.println(workers[i].toString()+" dependent: "+payrolls[i].getDependents());

  

System.out.print("Enter hours worked for "+workers[i].getname()+": ");

int hours = scan.nextInt();

scan.nextLine();

payrolls[i].PrintPayStub(hours);

}

}

}

Solutions

Expert Solution

update 2 methods

1) PrintPayStub in payroll.java

2)calculateRegPay in worker.java

please find the below code for the same

package demo;

public class Worker {

   // Member variables

   private String name;

   private String employeeId;

   private boolean dayShift;

   private double HourlyPay;
   // The default constructor

   public Worker() {

       this.name = "";

       this.employeeId = "";

       this.dayShift = false;

       this.HourlyPay = 0.0;

   }

   public Worker(String name, String employeeId, boolean dayShift, double hourlyPay) {

       super();

       this.name = name;

       this.employeeId = employeeId;

       this.dayShift = dayShift;

       HourlyPay = hourlyPay;

   }

   public Worker(Worker w) {
       this.name = w.name;

       this.employeeId = w.employeeId;

       this.dayShift = w.dayShift;

       this.HourlyPay = w.HourlyPay;
   }
   // This method sets the name of the worker

   public void setName(String n) {

       this.name = n;

   }
   // This method sets the employee Id

   public void setemployeeId(String i) {

       this.employeeId = i;

   }
   // This method sets the day shift

   public void setdayShift(boolean s) {

       this.dayShift = s;

   }
   // This method sets the hourly pay

   public void setHourlyPay(double p) {

       this.HourlyPay = p;

   }
   // This method returns the name of the worker

   public String getname() {

       return this.name;

   }
   // This method returns the employee Id

   public String getemployeeId() {

       return this.employeeId;

   }
   // This method returns if the worker is in day shift

   public boolean getdayShift() {

       return this.dayShift;

   }
   // This method returns the hourly pay

   public double getHourlyPay() {

       return this.HourlyPay;

   }
   // This method calculates the overtime pay

   public double calculateOvertimePay(int hours) {
       return (hours - 40) * 1.5 * HourlyPay;

   }
   // This method calculates and returns regular pay

   public double calculateRegPay(int hours) {
       if(hours>=40) {
       return HourlyPay* 40;
       }else {
           return HourlyPay* hours;
       }

   }

   @Override

   public String toString() {

       return "Worker name=" + name + ", employeeId=" + employeeId + ", dayShift=" + dayShift + ", HourlyPay="

               + HourlyPay;

   }

}

package demo;

public class Payroll {
   private Worker w;

   private int dependents;

   private static final double STATE_TAX = 0.10;

   private static final double FED_TAX = 0.05;

   public Payroll() {
       this.w = new Worker();

       this.dependents = 0;

   }

   public Payroll(String name, String id, double pay, boolean s, int d) {
       this.w = new Worker(name, id, s, pay);

       this.dependents = d;

   }

   public Payroll(Worker w, int dependents) {

       super();

       this.w = w;

       this.dependents = dependents;

   }

   public Worker getW() {

       return w;

   }

   public void setW(Worker w) {

       this.w = w;

   }

   public int getDependents() {

       return dependents;

   }

   public void setDependents(int dependents) {

       this.dependents = dependents;

   }

   public double calculateStateTax(int hours) {
       return (w.calculateRegPay(hours) + w.calculateOvertimePay(hours)) * STATE_TAX;

   }

   public double calculateFedTax(int hours) {
       return (w.calculateRegPay(hours) + w.calculateOvertimePay(hours)) * FED_TAX;

   }

   public void PrintPayStub(int hours) {
       double regPay, overPay;
       if (hours <= 40) {
// get the regular pay
           regPay = w.calculateRegPay(hours) - calculateStateTax(hours) - calculateFedTax(hours)
                   + (dependents * .03 * w.calculateRegPay(hours));
           overPay = 0;
       } else {
// get the overtime pay
           regPay = 40 * w.getHourlyPay() - calculateStateTax(40) - calculateFedTax(40)+ (dependents * .03 * w.calculateRegPay(40));
           overPay = w.calculateOvertimePay(hours) - (calculateStateTax(hours)-calculateStateTax(40)) - (calculateFedTax(hours)-calculateFedTax(40))
                   + (dependents * .02 * w.calculateOvertimePay(hours));
       }
// display the pay Stub
       System.out.println("\nName: \t" + w.getname());
       System.out.println("Employee ID: " + w.getemployeeId());
       System.out.print("Shift: ");
       if (w.getdayShift())
           System.out.println("\t\t day");
       else
           System.out.println("\t\tnight");
       System.out.printf("Hourly Pay: $ %7.2f", w.getHourlyPay());
       System.out.printf("\nRegular Pay: $ %.2f", regPay);
       System.out.printf("\nOvertime Pay: $ %4.2f", overPay);
       System.out.printf("\nGross Pay: $ %8.2f\n", (regPay + overPay));
   }

}

package demo;

import java.util.Scanner;

public class WorkerPayrollTest {
   public static void main(String[] args) {
       Worker[] workers = new Worker[5];

       Payroll[] payrolls = new Payroll[5];
       Scanner scan = new Scanner(System.in);
       for (int i = 0; i < workers.length; i++) {
           System.out.print("Enter worker name: ");

           String name = scan.nextLine();

           System.out.print("Enter id: ");

           String id = scan.nextLine();

           System.out.print("Hourly Pay: ");

           double pay = scan.nextDouble();

           scan.nextLine();

           System.out.print("Is day shift: ");

           boolean shift = scan.nextBoolean();

           scan.nextLine();
           workers[i] = new Worker(name, id, shift, pay);
       }

       for (int i = 0; i < payrolls.length; i++) {

           System.out.println(workers[i].toString());

           System.out.print("Enter dependent: ");

           int dependents = scan.nextInt();

           scan.nextLine();

           payrolls[i] = new Payroll(workers[i], dependents);

       }

       for (int i = 0; i < payrolls.length; i++) {

           System.out.println(workers[i].toString() + " dependent: " + payrolls[i].getDependents());

           System.out.print("Enter hours worked for " + workers[i].getname() + ": ");

           int hours = scan.nextInt();

           scan.nextLine();

           payrolls[i].PrintPayStub(hours);

       }

   }

}


Related Solutions

Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write a java program with the following classes: Class Player Method Explanation: play : will use...
Write a java program with the following classes: Class Player Method Explanation: play : will use a loop to generate a series of random numbers and add them to a total, which will be assigned to the variable score. decideRank: will set the instance variable rank to “Level 1”, “Level 2”, “Level 3”, “Level 4” based on the value of score, and return that string. getScore : will return score. toString: will return a string of name, score and rank....
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
java code Add the following methods to the LinkedQueue class, and create a test driver for...
java code Add the following methods to the LinkedQueue class, and create a test driver for each to show that they work correctly. In order to practice your linked list cod- ing skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously de?ined public methods of the class. String toString() creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging...
Create a (partial) BST class and a driver program to test it. The tree node will...
Create a (partial) BST class and a driver program to test it. The tree node will store integers as the data/key field (single field). Note that you will need to guarantee there are no duplicates in your insert function (the tree should refuse to insert a duplicate key). Call your files “tree.h”, “tree.cpp” and “main.cpp”. In addition, draw a picture of your tree (see note about random values below) Public methods to include: Constructor Copy Constructor Overloaded Assignment Operator Destructor...
Write these java classes: 1) DynArray.java: a class that models some of the functionality of the...
Write these java classes: 1) DynArray.java: a class that models some of the functionality of the Java ArrayList. This class is not complete and must be modified as such: Write the method body for the default constructor Write the method body for the methods: arraySize(), elements(), grow(), shrink(). The incomplete code is provided here: public class DynArray { private double[] array; private int size; private int nextIndex;    public int arraySize() { }    public int elements() { } public...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
What we want the program to do: We need to write a program, in Java, that...
What we want the program to do: We need to write a program, in Java, that will let the pilot issue commands to the aircraft to get it down safely on the flight deck. The program starts by prompting (asking) the user to enter the (start) approach speed in knots. A knot is a nautical mile and is the unit used in the navy and by the navy pilots. After the user enters the approach speed, the user is then...
Write a java program that has a class named Octagon that extends the class Circ and...
Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables. Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT