anonymous
2008-06-27 23:16:57 UTC
The next step I had to do was modify the payroll program application so it continues to request employee information until the user enters stop as the employee name. In addition, program the application to check that the hourly rate and number of hours worked are positive numbers. If either the hourly rate or the number of hours worked is not a positive value, the application should prompt the user to enter a positive amount.
My program and what my instructor said are below:
public class Payroll{
* myname
* 06/20/08
* payroll/calculation
System.out.print("Enter employee name: ");
employee = Input.readString();
while (employee.equals(""))
{
System.out.print("Enter proper employee name: ");
employee = Input.readString();
continue;
}
// hours worked
while (!hours_valid)
{
System.out.print("How many hours did " + employee + " work? ");
hours = Input.readDouble();
while (hours < 0)
{
System.out.print("Enter proper number of hours: ");
hours = Input.readDouble();
continue;
}
hours_valid = true;
}
// rate
while (!rate_valid)
{
System.out.print("How much does " + employee + " make per hour? ");
rate = Input.readDouble();
while (rate < 0)
{
System.out.print("Enter proper number for rate: ");
rate = Input.readDouble();
continue;
}
rate_valid = true;
}
// compute pay check
double pay = rate * hours;
NumberFormat fmt = NumberFormat.getCurrencyInstance();
System.out.println("\n" + employee + " worked for " + hours
+ " hours at " + fmt.format(rate) + "/hr; paycheck = "
+ fmt.format(pay));
}
}
Instructor comments:
You still need to cover some of the basics – IE: importing classes, the main method. This was a 50 point assignment. Here is what I got so you can see where I made my mistakes and help me change this.
The application compiles and runs 6/10
The application properly employs the use of a loop to request multiple employee info 5/20
Now I have to modify the 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.
Please help!
Thank you for your time!