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

QUESTION #2: - Employee.java - PayProgram.java - UML class diagram Employee Exer

ID: 3814282 • Letter: Q

Question

QUESTION #2:
   - Employee.java
   - PayProgram.java
   - UML class diagram

Employee Exercise
- Start jGrasp)
- Choose File/Close All to close all your currently open files.
- Choose File/New/Java to begin a new Java class in the edit window.
- Using the steps in the Practice Problems as a model, translate the pseudocode for the classes
below into Java and create the classes in Java using jGrasp. Take note that the payRate,
hoursWorked and grossPay are type double in Java.

Class Employee

    Private Real payRate

    Private Real hoursWorked

    Private Real grossPay

    Public Module Employee ( )

        Set payRate = 0.0

        Set hoursWorked = 0.0

        Set grossPay = 0.0

    End Module

    Public Function Real getPayRate ( )

        Return payRate

    End Function

    Public Function Real getHoursWorked ( )

        Return hoursWorked

    End Function

    Public Function Real getGrossPay ( )

        Return grossPay

    End Function

    Public Module setPayRate (Real newPayRate)

        If newPayRate > 0 Then

            Set payRate = newPayRate

        Else

            Display newPayRate, " is not a valid pay rate."

            Set payRate = 0

        End If

    End Module

    Public Module setHoursWorked (Real newHoursWorked)

        If newHoursWorked > 0 Then

            Set hoursWorked = newHoursWorked

        Else

            Display newHoursWorked, " is not a valid value for hours worked."

            Set hoursWorked = 0

        End If

    End Module

    Public Module computeGrossPay ( )

        Set grossPay = payRate * hoursWorked

        Display "Gross pay is", grossPay

    End Module

End Class

- Save the file by choosing File/Save As using the name Employee.java. Make sure the class
compiles without errors before continuing.

- Choose File/New/Java to begin a new Java class in the edit window. Create a new class
  named PayProgram, save it as PayProgram.java, and translate the following pseudocode
into Java.

Module main()

    Declare Employee julie

    Set julie = New Employee()

    Call julie.setPayRate (18.75)

    Call julie.setHoursWorked (47.5)

    Call julie.computeGrossPay ( )

End Module

- After you have translated the design into a Java program, compile both classes. Correct any
syntax errors before continuing.

- Run the PayProgram

Explanation / Answer

// Employee.java
public class Employee
{

private double payRate;
private double hoursWorked;
private double grossPay;

public void Employee ( )
{ payRate = 0.0;
hoursWorked = 0.0;
grossPay = 0.0;
}

public double getPayRate ( )
{ return payRate;
}

public double getHoursWorked ( )
{ return hoursWorked;
}

public double getGrossPay ( )
{ return grossPay;
}

public void setPayRate (double newPayRate)
{ if (newPayRate > 0)
payRate = newPayRate;
else
{
System.out.println(newPayRate + " is not a valid pay rate.");
payRate = 0;
}
}

public void setHoursWorked (double newHoursWorked)
{ if (newHoursWorked > 0)
hoursWorked = newHoursWorked;
else
{
System.out.println(newHoursWorked + " is not a valid value for hours worked.");
hoursWorked = 0;
}

}

public void computeGrossPay ( )
{   
grossPay = payRate * hoursWorked;
System.out.println("Gross pay is " + grossPay);
}

}

//PayProgram.java

public class PayProgram
{
public static void main(String[] args)
{
    Employee julie = new Employee();

julie.setPayRate (18.75);
julie.setHoursWorked (47.5);
julie.computeGrossPay ( );
}

}

/*
output:

Gross pay is 890.625

*/

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