This is the third time Im posting this question please rea

                                              ***** This is the third time I\'m posting this question****

       ** please read the instructions....There is an output sample on the last page, please scroll down to see it.**

                                                               Tell me What other imformation do you need?

Solution

import java.util.ArrayList;

public class EmployeeDriver {

   public static void main(String args[]) {
      
       /* Creating a new paystub */
       PayStub payStub1 = new PayStub();
       payStub1.editHours(1, 3, 9);
       payStub1.editHours(1, 6, 4);
       payStub1.editHours(2, 4, 12);
       payStub1.printHours();
      
       /* Creating an employee */
       Employee employee = new Employee(17);
       payStub1.setHourlyRate(employee.getHourlyRate());
       employee.addPayStub(payStub1);
       employee.setHourlyRate(17.56);
      
       PayStub payStub2 = new PayStub();
       payStub2.editHours(1, 1, 4);
       payStub2.editHours(1, 7, 20);
       payStub2.editHours(2, 1, 15);
       payStub2.editHours(2, 4, 6);
       payStub2.setHourlyRate(employee.getHourlyRate());
      
       employee.addPayStub(payStub2);
       employee.printIncomeHistory();
   }
}


/**
* Represent a paystub, which typically contains two week\'s data on
* hours worked during those two weeks
*
*/
class PayStub {
  
   /**
   * MEDICAL_INSURANCE_RATE is in $
   * and TAX_RATE is expressed in percentage
   */
   public static final double MEDICAL_INSURANCE_RATE = 50;
   public static final double TAX_RATE = 30;
   private double hourlyRate;
   private double[] hoursWorked;

   public PayStub() {
       this.hourlyRate = 15; /* 15$ per Hour by default */
       hoursWorked = new double[14];
   }

   public double getHourlyRate() {
       return hourlyRate;
   }

   public void setHourlyRate(double hourlyRate) {
       this.hourlyRate = hourlyRate;
   }

   public void editHours(int week, int day, double hoursWorked) {
      
       if (week > 2 || week < 1 || day > 7 || day < 1
               || hoursWorked < 0 || hoursWorked > 24) {
           return;
       }
       /*
       * Since we stored the two weeks in a one dimensional array,
       * we need to convert the week and day into corresponding
       * index of the array
       */
       int index = (week-1) * 7 + (day-1);
       this.hoursWorked[index] = hoursWorked;
   }
  
   public void printHours() {
       for (int i=0; i<7; i++) {
           System.out.println(\"Week 1 , Day \"+(i+1)+\", Hours Worked: \"+hoursWorked[i]);
       }
       for (int i=7; i<14; i++) {
           System.out.println(\"Week 2 , Day \"+(i+1)+\", Hours Worked: \"+hoursWorked[i]);
       }
       System.out.println();
   }
  
   public double calculateRegularHours() {
       int regularHours = 0;
       for (int i=0; i<14; i++) {
           if (hoursWorked[i] <= 8) {
               regularHours += hoursWorked[i];
           }
           else {
               regularHours += 8;
           }
       }
       return regularHours;
   }
  
   public double calculateOverTimeHours() {
       int overTime = 0;
       for (int i=0; i<14; i++) {
           if (hoursWorked[i] > 8) {
               overTime += (hoursWorked[i] - 8);
           }
       }
       return overTime;
   }
  
   public void printPayStub() {
       double regHours = calculateRegularHours();
       double overTimeHours = calculateOverTimeHours();
       double grossIncome = (regHours + overTimeHours) * hourlyRate;
       double deductions = (grossIncome * PayStub.TAX_RATE/100.0) + PayStub.MEDICAL_INSURANCE_RATE;
       double takeHome = grossIncome - deductions;
       System.out.println(\"Regular Hours Worked : \" + regHours);
       System.out.println(\"Overtime Hours Worked : \" + overTimeHours);
       System.out.println(\"Gross Income : $\" + grossIncome);
       System.out.println(\"Deduction : $\" + deductions);
       System.out.println(\"Takehome Income : $\" + takeHome+\"\ \");
   }
}

/**
* This class represents an employee and each employee
* will typically have several paystub
*
*/
class Employee {
  
   private double hourlyRate;
   private ArrayList<PayStub> payStubArray;

  
   public Employee(double hourlyRate) {
       this.hourlyRate = hourlyRate;
       payStubArray = new ArrayList<PayStub>();
   }
  
   public void addPayStub(PayStub payStub) {
       payStubArray.add(payStub);
   }
  
   public double getHourlyRate() {
       return hourlyRate;
   }

   public void setHourlyRate(double hourlyRate) {
       this.hourlyRate = hourlyRate;
   }

   public void printIncomeHistory() {
       int i=1;
       for (PayStub payStub : payStubArray) {
           System.out.println(\"*********** PayStub - \"+i+\"*************\");
           payStub.printPayStub();
           i++;
       }
   }
}

 ***** This is the third time I\'m posting this question**** ** please read the instructions....There is an output sample on the last page, please scroll down t
 ***** This is the third time I\'m posting this question**** ** please read the instructions....There is an output sample on the last page, please scroll down t
 ***** This is the third time I\'m posting this question**** ** please read the instructions....There is an output sample on the last page, please scroll down t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site