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

Skills Expected All the skills from previous Assignment(s) Class Object and Desi

ID: 3796300 • Letter: S

Question

Skills Expected
All the skills from previous Assignment(s)
Class Object and Design, including but not limited to

o Instance Variableso

Getter and Setter (including input validation in Setters)

o Constructoro Methods

Assignment Description
You will write three Class objects (and subsequently submit three .java files):

Paystub

Employee

EmployeeDriver

Class Design: Paystub

The Paystub class is intended to be an abstract and simplified representation of a paystub.  A paystubwill typically contain two weeks’ data on hours worked during those two weeks.

Data to store
Hourly Rate

Make this a private instance variable with both public getter and setter Hours Worked (store this as an array of hours worked for each day of the two weeks)

o Make this a private instance variable without getter or setter (we’ll do something else)

Medical Insurance Rate ($50 – store this as a public constant) Tax Rate (30% - store this as a public constant)

Available actions
Constructor – set the hourly rate to $15/hr. by default Edit Hours – This should be a method that takes in as argument the week and day to edit as well

as the number of hours worked on that day.  Be sure to check for valid input. Print Hours – This should be a method that prints out (e.g. to the console) hours worked forevery day of the two weeks. Calculate Regular Hours – A method that returns the number of regular hours worked (total)during the two weeks. Calculate Overtime Hours – Return the number of overtime hours worked (total). Print Paystub – Print out a paystub as in HW5.

Class Design: Employee
The Employee class is intended to be an abstract and simplified representation of a single employee.  Anemployee typically will have several paystubs.

Data to store
Hourly rate. This should be a private instance variable with both public getter and setter.

An array of Paystub. This should be a private instance variable without getter or setter.

Available actions
Constructor – Take in as argument hourly rate of the employee and set the instance variable. Add Paystub – A method that takes in as argument a Paystub and add it to the array. Print Income History – Prints all paystubs that the employee has received so far.

Class Design: EmployeeDriver
The textbook defines a “driver program” as “A program that does nothing but test a method.” In otherwords, EmployeeDriver will be used to test the methods you implemented for the Employee class,which will result in testing both the Paystub and Employee classes, by extension.Write a main method that meets the Grading Criteria below.

Paystub class object (10 Points Total)

o [1 point] Correct Class definition/syntaxo [1 point] Correctly stores all required data (“Data to store” section)o [2 points] Getters and Setters for Hourly Rate (including input validation)o [1 point] Constructoro [1 point] Edit Hours method (including input validation)o [1 point] Print Hours methodo [1 point] Calculate Regular Hours methodo [1 point] Calculate Overtime Hours methodo [1 point] Print Paystub method

Employee class object (7 Points Total)

o [1 point] Correct Class definition/syntaxo [1 point] Correctly stores all required data (“Data to store” section)o [2 points] Getters and Setters for Hourly Rate (including input validation)o [1 point] Constructoro [1 point] Add Paystub methodo [1 point] Print Income History method

EmployeeDriver class object (10 Points Total)o [1 point] Create Paystub

o [1 point] Edit Hours (contains regular and overtime hours for both weeks)o [1 point] Print Hourso [1 point] Create Employee with $17/hr. hourly rate.o [1 point] Change Paystub hourly rate to match Employee hourly rateo [1 point] Add Paystub to Employeeo [1 point] Change Employee hourly rate to $17.56/hr.o [1 point] Create another instance of Paystub with new hours and update the hourly rateto match the new employee hourly rateo [1 point] Add the second Paystub to Employeeo [1 point] Print employee income history

[1 point] Method JavaDoc: description, @param, @return [1 Point] Descriptive variable names [1 Point] Appropriate class header comment block

output looks like

Week 1, Day 1, Hours Worked: 0.00

Week 1, Day 2, Hours Worked: 0.00

Week 1, Day 3, Hours Worked: 9.00

Week 1, Day 4, Hours Worked: 0.00

Week 1, Day 5, Hours Worked: 0.00

Week 1, Day 6, Hours Worked: 4.00

Week 1, Day 7, Hours Worked: 0.00

Week 2, Day 1, Hours Worked: 0.00

Week 2, Day 2, Hours Worked: 0.00

Week 2, Day 3, Hours Worked: 0.00

Week 2, Day 4, Hours Worked: 12.00

Week 2, Day 5, Hours Worked: 0.00

Week 2, Day 6, Hours Worked: 0.00

Week 2, Day 7, Hours Worked: 0.00

-----------------Paystub 1-----------------

Regular Hours Worked: 20.0

Overtime Hours Worked: 5.0

Gross Income: $467.50

Deductions: $175.25

Takehome Income: $292.25

-----------------Paystub 2-----------------

Regular Hours Worked: 26.0

Overtime Hours Worked: 1.5

Gross Income: $496.07

Deductions: $183.82

Takehome Income: $312.25

Explanation / Answer

Here is the code for above scenario

PayStub

package demo;

import java.util.ArrayList;

public class PayStub {
   private int hourlyRate;
   private int[] hoursWorked = new int[14];
   public static final int medicalInsuranceRate = 50;
   public static final int taxRate = 30 ;
  
   public int getHourlyRate() {
       return hourlyRate;
   }

   public void setHourlyRate(int hourlyRate) {
       this.hourlyRate = hourlyRate;
   }
  
   PayStub(){
       hourlyRate= 15;
   }
  
   public void editHours(int week, int day , int hours){
       if(week>2){
           System.out.println("Enter week not more than 2 ");
       }
       if(week<0){
           System.out.println("Invalid week");
       }
       if(day>7){
           System.out.println("Invalid day");
       }
       if(day<0){
           System.out.println("Invalid day");
       }
       if(hours>24){
           System.out.println("Invalid hours");
       }
       if(hours< 0){
           System.out.println("Invalid hours");
       }
       if(week==1){
           hoursWorked[day-1]= hours;
       }
       else{
           hoursWorked[7+day-1]= hours;
       }
   }
  
   public void printHours(){
       int i;
       for(i=1;i<=7;i++){
           System.out.println("Week 1, Day "+i+", Hours:"+hoursWorked[i-1]);
       }
       for(i=1;i<=7;i++){
           System.out.println("Week 2, Day "+i+", Hours:"+hoursWorked[i-1]);
       }
   }
  
   public int calculateRegularHours(){
       int i;
       int total=0;
       for(i=0;i<14;i++){
           total=total+hoursWorked[i];
       }
       return total;
   }
  
   public int overTime(){
       int i;
       int total=0;
       for(i=0;i<14;i++){
           total=total+hoursWorked[i];
       }
       return total-20;
   }
  
   public void printStub(){
       int i=0;
       for(i=1;i<=7;i++){
           System.out.println("Week 1, Day "+i+", Hours:"+hoursWorked[i-1]);
       }
       for(i=1;i<=7;i++){
           System.out.println("Week 2, Day "+i+", Hours:"+hoursWorked[i-1]);
       }
       System.out.println("Regular Hours Worked:"+calculateRegularHours());
       System.out.println("Overtime:"+overTime());
   }
}

Employee class

package demo;

import java.util.ArrayList;

public class Employee {
   private int hourlyRate;
   private ArrayList<PayStub> payStubList = new ArrayList<PayStub>();
  
   Employee(int hourlyRate){
       this.hourlyRate=hourlyRate;
   }
  
   public void addPayStub(PayStub paystub){
       payStubList.add(paystub);
   }
  
   public int getHourlyRate() {
       return hourlyRate;
   }

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

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