Last week I developed a payroll program that duffy helped out quite a bit with. This week we need to improve on the program a little more. Here is what the teacher is asking:
"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. "
I'm a little unsure how to create the class that stores the employee info to be carried to each step. The teacher explained that there should be two classes, employee and payroll. I'm not sure how to set up the employee class. here is my code:
// Multiplication.java
// Payroll program
import java.util.Scanner;
public class Payroll
{
private static final String STOP = "stop";
public static void main(String args[])
{
Scanner scanner = new Scanner (System.in);
System.out.print("Please enter name < enter 'stop' to exit program:");
String nameOfEmployee = scanner.nextLine();
if (!nameOfEmployee.equals(STOP))
{
double rate = 0;
double hours = 0;
double totalPay;
do
{
System.out.print("Enter rate:$ ");
rate = scanner.nextDouble();
if ( rate >=0 )
break;
else
{
System.out.print ( "Please enter a postive number." );
}
} while (rate < 0);
System.out.println ("rate: " + rate);
do
{
System.out.print("Enter hours: ");
hours = scanner.nextDouble();
if ( hours >= 0 )
break;
else
{
System.out.print ( "Please enter a postive number.");
}
} while (hours < 0 );
System.out.println ("hours: " + hours);
totalPay = rate * hours;
scanner.nextLine();
System.out.printf("%s pay is $ %.2f\n", nameOfEmployee, totalPay);
}
}
}
Any advice would be greatly appreciated. Oh I also need to figure out how to keep the program going and having only 'stop' end it. Right now it just cycles once.
Message was edited by:
stevedub