I have a project due in the class which is to script up java code.
Code must do the following:
Ask for Name
Ask for hourly wage
Ask for hours worked per week
Display weekly pay.
If hourly wage or hours worked are a negative number display error and loop until a positive number is provided.
Program must run until the user enters "STOP" as the name.
I have all of the code working but the loop until the user enters "STOP" as the name. The code is as follows.
Code: Select all
// Assignment: Payroll.java// Payroll Program Part 2import java.util.Scanner; // program uses class Scanner public class Payroll{ // main method begins execution of Java application public static void main( String args[] ) { // create Scanner to obtain input from command window Scanner input = new Scanner( System.in ); float weeklyPay; // wage times hours with decimal point System.out.printf( "Enter Employee's Name or Stop, to quit: " ); //ask for name or type stop to quit String theName = input.nextLine(); // Employee's Name System.out.println(); // output blank line System.out.printf( "Enter employee's hourly wage: " ); // ask for hourly wage float wage = input.nextFloat(); // read hourly wage from user System.out.println(); // output blank line do { System.out.printf( "Please enter a positive number for hourly wage.\n" ); System.out.println(); System.out.printf( "Enter employee's hourly wage: " ); // ask for hourly wage wage = input.nextFloat(); System.out.println(); // output blank line } while (wage <= 0); System.out.printf( "Enter number of hours worked: " ); // ask for hours float hours = input.nextFloat(); // read hours work from user System.out.println(); // output blank line do { System.out.printf( "Please enter a positive number of hours.\n" ); System.out.println(); System.out.printf( "Enter number of hours worked: " ); // ask for hourly wage hours = input.nextFloat(); System.out.println(); // output blank line } while (hours <= 0); weeklyPay = wage * hours; // multiply to get weekly pay System.out.printf("The weekly pay for %s is $%.2f this week", theName, weeklyPay ); } // end method main } // end class Payroll
Some advise would be helpful even if its a site that can provide more detail then my school materials.