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

Create a Class Assignment 1. Create a class as described below Class Name: Pay F

ID: 3667413 • Letter: C

Question

Create a Class Assignment 1. Create a class as described below Class Name: Pay Fields: hoursWorked payRate grossPay Constructors:A default constructor to initialize the fields. The payRate field should be set to $9.75 and the hours worked field to zero. Another constructor with one argument, the number of hours worked, It should assign this value to the appropriate field, set the pay rate field to the default value of $9.75. Methods: getHours0 This methods returns the hourWorked field value. getPayRate0- This method returns the payRate field value, getGrossPayO-This method returns the grossPay field value, calcGrossPay0- This method calculated the gross pay for an instance of the class (hours* payRate) the number of hours setHours0- This method has one argument worked, the current pay rate to setPayRate0 This method has one argument be assigned. Save this file with the appropriate file name, Compile the file, 2. Create another class named testPay that uses the above class, This class should have a mainO method that behaves as follows 1. Create two instances of the Pay class: Emp1 that uses the default constructor, Emp2 that creates an instance with hours worked equal to 36, 2, Change the hours worked for Emp1 to 48, 3, Charge the pay rate for Emp2 to $15.60, 4, Calculate the gross pay for both instances. 5, Display the hours worked, pay rate, and gross pay for both instances with appropriate labels, Save this file, compile, and execute it 11:00 AM 2/12/2016

Explanation / Answer


class Pay
{
   public int hoursWorked;
   public int payRate;
   public double grossPay;

   Pay()
   {
       hoursWorked = 0;
       payRate = 9.75;
       grossPay = 0;
   }
  
   Pay(int hoursWorked)
   {
       hoursWorked = hoursWorked;
       payRate = 9.75;
       grossPay = 0.0;
   }
  
   public int getHours()
   {
       return hoursWorked;
   }
  
   public int getpayRate()
   {
       return payRate;
   }
  
   public double grossPay()
   {
       return grossPay;
   }

   public double calcGrossspay()
   {
       return hoursWorked * payRate;
   }
  
   public void setHours(int hoursWorked)
   {
       hoursWorked = hoursWorked;
   }
  
   public void setPayRate(int payRate)
   {
       payRate = payRate;
   }
}

public class testpPay
{
   public static void main(String[] args)
   {
       Pay Emp1[] = new Pay();
       Pay Emp2[] = new Pay(36);
       Emp1.setHours(48);
       Emp2.setPayRate(15.60);
       double result = Emp1.calcGrossspay();
       double result2 = Emp2.calcGrossspay();
      
       System.out.println("Employee 1 Details");
       System.out.println("Hours Worked: "+ Emp1.getHours() + " Pay Rate :"+ Emp1.getpayRate()+ " Gross Pay :"+Emp1.grossPay());
      
       System.out.println("Employee 2 Details");
       System.out.println("Hours Worked: "+ Emp2.getHours() + " Pay Rate :"+ Emp2.getpayRate() +" Gross Pay :"+Emp2.grossPay());
   }
}

Solution for Question 2:

import java.util.Scanner;
class Pay
{
   public int hoursWorked;
   public int payRate;
   public double grossPay;

   Pay()
   {
       hoursWorked = 0;
       payRate = 9.75;
       grossPay = 0;
   }
  
   Pay(int hoursWorked)
   {
       hoursWorked = hoursWorked;
       payRate = 9.75;
       grossPay = 0.0;
   }
  
   public int getHours()
   {
       return hoursWorked;
   }
  
   public int getpayRate()
   {
       return payRate;
   }
  
   public double grossPay()
   {
       return grossPay;
   }

   public double calcGrossspay()
   {
       return hoursWorked * payRate;
   }
  
   public void setHours(int hoursWorked)
   {
       hoursWorked = hoursWorked;
   }
  
   public void setPayRate(int payRate)
   {
       payRate = payRate;
   }
}

public class testACompany
{
   public static void main(String[] args)
   {
       Pay boss,manager(25), accountant(17);
       accountant.setHours(38);
       System.out.println("Enter Number of Hours");
       Scanner sc = new Scanner(System.in);
       int hours = sc.hasNextInt();
       boss.setHours(hours);
      
       System.out.println("Enter Number of PayRate");
       int payrate = sc.hasNextInt();
       boss.setHours(payrate);
      
       System.out.println("Enter Number of PayRate");
       int payrate = sc.hasNextInt();
       accountant.setHours(payrate);
      
       double re1 = boss.calcGrossspay();
       double re2 = manager.calcGrossspay();
       double re3 = accountant.calcGrossspay();
      
       System.out.println("Boss Details");
       System.out.println("Hours Worked: "+ boss.getHours() + " Pay Rate :"+ boss.getpayRate()+ " Gross Pay :"+boss.grossPay());
      
       System.out.println("Manager Details");
       System.out.println("Hours Worked: "+ manager.getHours() + " Pay Rate :"+ manager.getpayRate() +" Gross Pay :"+manager.grossPay());
      
       System.out.println("Accountant Details");
       System.out.println("Hours Worked: "+ accountant.getHours() + " Pay Rate :"+ accountant.getpayRate() +" Gross Pay :"+accountant.grossPay());
      
   }
}