Looking for some advise as to correct these 2 problems i had with my past homework.
1.Include a condition to leave all your loops instead of using a break to leave. No infinite loops are needed.
2.You need to use proper indentation and there is no indentation here.
import java.util.Scanner; // This program uses class Scanner
public class Payroll {
// main method begins execution of
Java Application
public static void main(
String args[]) {
//create a scanner object to obtain input from command window
Scanner input = new Scanner(System.in);
String employeeName = ""; //input employee name
double hourlyWage;
double hoursWorked;
double weeklyPay;
// loop until the user enters 'stop' as the name of the employee.
do {
// Get Employee Name
System.out.print("Enter Name of Employee:");
employeeName = input.next();
// if the employee name is 'stop', then exit the loop.
if (employeeName.equals("stop")) {
break;
}
// ask for hourly wage
System.out.print("Enter hourly Wage:");
hourlyWage = input.nextDouble();
// require that the hourly wage is a non-negative
while (hourlyWage < 0.0) {
System.out.print("Hourly wage must be a positive number. Please enter a positive hourly wage:");//prompt
hourlyWage = input.nextDouble();
input.nextLine();
}
// ask the hours worked
System.out.print("Enter hours worked:");
hoursWorked = input.nextDouble();
// require that hours worked be a non-negative number
while (hoursWorked < 0.0) {
System.out.print("Hours worked must be a positive number. Please enter a positive number of hours:");//prompt
hoursWorked=input.nextDouble();
input.nextLine();
}
weeklyPay = hourlyWage * hoursWorked;
System.out.printf("The employee, %s, was paid $ %.2f this week.\n\n", employeeName, weeklyPay);
} while (true);
} //end method main
} //end class Payroll
[ March 14, 2008: Message edited by: Jim Yingst ]