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

Create a class named EmployeeRecords. Data fields included are employee name, em

ID: 3625898 • Letter: C

Question

Create a class named EmployeeRecords. Data fields included are employee name, employee ID, hours worked, hourly pay rate. Save the class as EmployeeRecords.java and submit to your instructor.
Create a class named TestEmployeeRecords that instantiates three EmployeeRecords objects and demonstrates the use of the EmployeeRecords set and get methods. Provide values for each field for each employee. The data should not be user prompted. Include a method named calculatePay() to compute the gross pay for each employee. This method should use the set and get methods of the EmployeeRecords class. Create an additional method displayInformation() to display the employee information including employee name, employee ID, hours worked, hourly pay rate, and gross pay. This method should use the set and get methods of the EmployeeRecords class. Include required comments. Save the class as TestEmployeeRecords.java.
//Creating class
public class EmployeeRecords
{
private String name;
private int empId;
private int hrsWorked;
private double rate;/*All the variables I'll need.*/
public EmployeeRecords(String firstLast, int num, int work, double pay)/*Constructor method.*/
{
//Populate the method
name=firstLast;
empId=num;
hrsWorked=work;
rate=pay;
}
//8 get and set methods
public String getName()
{
return name;
}
public int getEmpId()
{
return empId;
}
public int getHrsWorked()
{
return hrsWorked;
}
public double getRate()
{
return rate;
}
public void setName(String newName)
{
name=newName;
}
public void setEmpId(int newEmpId)
{
empId=newEmpId;
}
public void setHrsWorked(int newHrsWorked)
{
hrsWorked=newHrsWorked;
}
public void setRate(double newRate)
{
rate=newRate;
}
//Display method
public void displayInformation()
{
System.out.println("Employee name: " + name);
System.out.println("Employee ID: " + empId);
System.out.println("Hours worked: " + hrsWorked);
System.out.println("Pay rate: " +rate);
}
}
//Will print three records
public class TestEmployeeRecords
{
public static void main(String[] args)
{

//constructor method
EmployeeRecords firstEmployeeRecords=new EmployeeRecords("Paul Smith", 67895, 40, 25.00);
EmployeeRecords secondEmployeeRecords=new EmployeeRecords("John Doe", 18310, 28, 12.50);
EmployeeRecords thirdEmployeeRecords=new EmployeeRecords("Jane Smith", 12345, 30, 22.00);
//displaying the records
firstEmployeeRecords.displayInformation();
secondEmployeeRecords.displayInformation();
thirdEmployeeRecords.displayInformation();
}

}

I can't figure it out how to create the calculatePay method.

Explanation / Answer

The pay for each employee should be hours worked * hourly pay rate, right? public static double calculatePay(int hrsWorked, double hrlyPay) { return hrsWorked*hrlyPay; } Note that the static keyword was added because we'll be using it in the class calling main. Inside static methods (like main), we can only call other static methods. If we need to use non-static methods, we have to call them from other classes. As i read from the text, you must use the gets to access each instance value of the numbers of worked hours and hourly pay. Note that in order to access static methods, we have to call it from the class they belong. double firstEmployeePay = TestEmployeeRecords.calculatePay(firstEmployeeRecords.getHrsWorked(), firstEmployeeRecords.getRate()); double secondEmployeePay = TestEmployeeRecords.calculatePay(secondEmployeeRecords.getHrsWorked(), secondEmployeeRecords.getRate()); double thirdEmployeePay = TestEmployeeRecords.calculatePay(thirdEmployeeRecords.getHrsWorked(), thirdEmployeeRecords.getRate()); System.out.println(firstEmployeePay); System.out.println(secondEmployeePay); System.out.println(thirdEmployeePay);

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