Hello,
I know this is an old post and sorry to bring it back to life but I have the same exact assignment. I read through your code, hardwired, and it seems I have made mine work in a different way. I understand a little able what you have done above but not enough to be able to implement it into my code. Without adding the code, can you explain a little bit or point me in the correct direction as to where I can understand better on where the constructors would appear and/or how to create a class to store the information?
import java.util.Scanner;
public class Main
{
double rate;
double hours;
String Empname;
// main method begins execution of Java application
public static void main(String args[])
{
boolean stop = false; // controls if loop below is executed
while (!stop)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
System.out.print("Enter employee's name or stop to quit: "); // prompt for name
String EmpName = input.nextLine(); // read employee's name entered
if (EmpName.equals("stop"))
{
System.out.println("This program has ended successfully.");
stop = true;
}
else
{
double PayRate; // First number multiplied
double HoursWorked; // Second number multiplied
double total; // Total of PayRate * HoursWorked
System.out.print("Enter the pay rate per hour of the employee: "); // prompt for rate
PayRate = input.nextDouble(); // read payrate of employee
while (PayRate <= 0) // Validate for positive number
{
System.out.println();
System.out.println("Pay rate must be a positve number. ");
System.out.print("Please enter pay rate per hour again: ");
PayRate = input.nextDouble();
System.out.println();
}
System.out.print("Enter the employee's hours worked this pay week: "); // prompt for Hours
HoursWorked = input.nextDouble();
while (HoursWorked <= 0) // validate for positive number
{
System.out.println();
System.out
.println("Hours worked must be a positive number. ");
System.out.print("Please enter hours worked this pay week again: ");
HoursWorked = input.nextDouble(); //read hourly rate of pay
System.out.println();
}
total = (double) PayRate * HoursWorked; // Multiply PayRate by HoursWorked
System.out.println();
System.out.println("Employee: " + EmpName); //display name
System.out.println("Number of hours worked this pay week: " + HoursWorked); //display hours worked
System.out.printf("Employee's Pay: $%,.2f\n", total); //display pay rate
System.out.println();
System.out.println();
} // end else
} //end while
} // end main
} // end class