Background:
Modify the Payroll Program so that it uses a class to store and retrieve the employee's
name, the hourly rate, and the number of hours worked. Use a constructor to initialize the
employee information, and a method within that class to calculate the weekly pay. Once
stop is entered as the employee name, the application should terminate. Make sure the
program maintains all the functionality required in previous assignments and your source
code is readable and well documented. Use feedback you have received from the
instructor to make any needed modifications.
here is what I have in the new class
package pay_1;
public class Employee {
public static String name1;
public static String name2;
public static double hoursWorked;
public static double payRate;
public Employee(String name1, String name2, double hoursWorked,
double payRate) {
super();
Employee.name1 = name1;
Employee.name2 = name2;
Employee.hoursWorked = hoursWorked;
Employee.payRate = payRate;
}
public String getName1() {
return name1;
}
public void setName1(String name1) {
Employee.name1 = name1;
}
public String getName2() {
return name2;
}
public void setName2(String name2) {
Employee.name2 = name2;
}
public double getHoursWorked() {
return hoursWorked;
}
public void setHoursWorked(double hoursWorked) {
Employee.hoursWorked = hoursWorked;
}
public double getPayRate() {
return payRate;
}
public void setPayRate(double payRate) {
Employee.payRate = payRate;
}
}
I have already completed the class to preform the calculations it reads:
package pay_1;
import java.util.Scanner;
public class Calcu {
// Program execution starts here
public static void main ( String [] args )
{
// Start Scanner
Scanner input = new Scanner (System.in);
String name;
String name2;
double payRate;
double hoursWorked;
// Begin User Input
System.out.println("Welcome:-)\nEnter employee's first name\nor type stop to quit");
name = input.next();
// loop until stop begins
while ( !name.equals("stop") )
{
System.out.println("Enter employee's last name");
name2 = input.next();// read last name from user
System.out.println("Enter Pay Rate\n$");
payRate = input.nextFloat(); // read hourly rate from user
// start pay rate while loop
while (payRate <= 0)
{
System.out.print( "Please use positive numbers: "); // prompt for input of positive number
payRate = input.nextFloat(); // read hourly rate from user
}
System.out.println("Enter number of hours worked");
hoursWorked = input.nextFloat(); // read hourly rate from user
// start hours worked loop for positive number
while (hoursWorked <= 0)
{
System.out.print("please use positive numbers"); // prompt for positive hourly rate
hoursWorked = input.nextFloat(); // user input
}
// Calculations Begin
Object product = payRate * hoursWorked;
//Display Results
System.out.println(name);//print first name
System.out.println(name2);//print last name
System.out.printf("total income this week is $%.2f\n", product);
//1st prompt for user input in loop
System.out.println("Enter employee's first name\nor type stop to quit");//
name = input.next();
}//end while
// goodbye message
System.out.println("Thank you for using my payroll program.");
}// End main method
}
When I run the program; how do I store and retrieve the data as directed above?