Hello,
I'm new to Java and am trying to create a simple payroll program that uses a while loop to repeat until the user enters "Stop" for the employee's name. I've tried everything I can think of and everything others have suggested and for some reason, I cannot get the program to differentiate between the word "Stop" or any other word. Could someone please help me figure out what I'm doing wrong? My code is as follows:
import java.util.Scanner; // imports scanner class for user input
public class Payrolltest
{
public static void main( String[] args ) // begins execution of program
{
Scanner input = new Scanner( System.in ); // creates a scanner to obtain user input
String Employee = "name"; // employee's name
double Hours = 0; // hours worked
double Rate = 0; // employee's pay rate
double Paycheck = 0; // amount of the paycheck
System.out.println(); // blank line for readability
while (!Employee.equals("Stop")) //begins the repetition loop for employee input until user enters the sentinel stop.
{
System.out.println ("Please enter the employee's name. Enter \"Stop\" to quit."); //prompts for the employee's name.
Employee = input.nextLine(); // read input from user and assign to Employee
System.out.println ("Enter hours worked:"); // prompt for hours worked
Hours = input.nextDouble(); // read input from user and assign to Hours
System.out.println ("Enter employee's hourly pay rate:"); // prompt for pay rate
Rate = input.nextDouble(); // read input from user and assign to Rate
Paycheck = Hours * Rate; // calculates amount for paycheck
System.out.println(); // blank line for readability
System.out.printf ("%s's paycheck is $%,.2f", Employee, Paycheck); // displays employee's name and paycheck amount
System.out.println(); // blank line for readability
System.out.printf ("Do you want to continue? enter the next employee's name or enter \"Stop\" to quit.)");
Employee = input.nextLine(); // read input from user and assign to Employee
} // end repetition loop for user input
System.out.printf ("Thank you for using the payroll program."); // goodbye message
} // end method main
} // end class Payroll
Thanks!