Hello,
The following is background on my assignment "Modify payroll program so that it uses a class to store and retrive the employee's name, 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 code is readable and well documented."
I have everything coded but my while loop for my program exit value is not working. Can someone let me know what I'm missing?
import java.util.ArrayList;
import java.util.Scanner; // program uses class Scanner
class EmployeeData { // start of EmployeeData class
EmployeeData(String newName, float newHourly, float newHours) {
name = newName; hourly = newHourly; hours = newHours;
}
public String getName() { return name; }
public float getProduct() { return hourly * hours; }
private String name;
private float hourly, hours;
} // end of EmployeeData class
public class Payroll4
{ // start of public class
private String EmployeeData; // employee information for this Payroll
private static int ArrayList;
private static int i;
// main method begins execution of java application
public static void main( String args[] )
{ // Start main method
ArrayList employees = new ArrayList ();
// create scanner to obtain input from command window
Scanner input = new Scanner ( System.in );
System.out.println();
System.out.print( "Enter employee name or stop to quit: " ); String empName = input.nextLine(); // read employee name
while (empName.equalsIgnoreCase("STOP") != true)
{
EmployeeData employee;
float hourly; // Employee Hourly Rate
float hours; // Employee Hours Worked
float product; // Employee Salary for Week
{
System.out.print( "Enter hourly rate: " ); // prompt
hourly = input.nextFloat(); // read hourly rate from user
while (hourly <= 0)
{
System.out.print( "Please Enter postive hourly rate: "); // prompt for postive hourly rate
hourly = input.nextFloat(); // read hourly rate from user
}
System.out.print( "Enter hours worked for week: "); // prompt for hours
hours = input.nextFloat(); //read number of hours worked
while (hours <= 0)
{
System.out.print( "Please enter postive hours worked: "); // prompt for postive hours worked
hours = input.nextFloat(); // read number of hours worked
}
employee = new EmployeeData(empName, hourly, hours) {
};
System.out.println();
System.out.print( employee.getName( ) ); // display employee name
System.out.printf( "'s Weekly pay: $%,.2f\n", employee.getProduct() ); // Display weekly pay
System.out.println();
System.out.println();
System.out.print( "Enter employee name or stop to quit: " ); // prompt for employee name
String empName = input.nextLine(); // read employee name
}
System.out.println();
System.out.println( "Thank you, Goodbye" );
} // end main method
}} // end class Payroll4