unreachable statement error

Could you please help me figure out what the problem with my code is? I get: C:\Documents and Settings\Sandy\My Documents\Payroll2.java:31: unreachable statement

System.out.println( "Enter Hourly Rate: "); // prompt

^

1 error

when I compile this:

// Payroll2.java

// A Payroll program with a while loop

// that continues until "stop" is used as the name

import java.util.Scanner; // program uses class Scanner

public class Payroll2

{

// main method begins execution of java application

public static void main(String args[])

{

// create a scanner to obtain input in command window

Scanner input = new Scanner( System.in );

String employeeName; // Name of employee

double hourlyRate; // Amount made in one hour

double hoursWorked; // Number of hours worked in one week

double weeklyPay; // The multiple of hourly rate and hours worked in one week

// while method employed to enter emplyee's name

while ( "employeeName" != "stop")

{

System.out.println("Enter an employee name(Input 'stop' when finished)\n\n"); //prompt

employeeName = input.nextLine(); // read employee name or stop

} // end while

// if...else method used to input hourly rate as a positive double

System.out.println( "Enter Hourly Rate: "); // prompt

hourlyRate = input.nextDouble(); // read hourly rate

if ( hourlyRate <= 0)

{

System.out.println( "Hourly Rate incorrect, please try again\n"); // error message

}// end if

else

{

System.out.println( "Correct Hourly Rate input, thank you\n\n"); // confirmation message

} // end else

// if...else method used to input hours worked

System.out.print( "Enter Hours Worked: "); // prompt

hoursWorked = input.nextDouble(); // read hours worked

if ( hoursWorked <= 0)

{

System.out.println( "Weekly hours worked is incorrect, please try again\n"); // error message

}// end if

else

{

System.out.println( "Correct weekly hours input, thank you\n\n"); // confirmation message

} // end else

// calculate weekly pay

weeklyPay = hourlyRate * hoursWorked; // multiply numbers

// display employee name and weekly pay

System.out.printf( "Weekly Pay for %s,is $%.2f\n", employeeName, weeklyPay);

System.out.println( "Thank you for using Payroll2\n"); // good bye message

} // end method main

} // end class Payroll2

[2552 byte] By [sandy_607a] at [2007-11-27 11:15:53]
# 1

Your method is guaranteed to return before you get to that statement. Check that your braces are correct, and make sure that you use braces even when there's only one line in the block. Also make sure your ifs and elses match up.

hunter9000a at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...
# 2

while ( "employeeName" != "stop")

is equivalent towhile (true)

Thus your while loop will never end, meaning it will never reach your next statement (which incidentally is the statement in question).

dwga at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...
# 3

regarding what dwg pointed out to you: You do know what to use instead of your current while loop:

while ( "employeeName" != "stop")

Right? If not, now's the time to speak up.

petes1234a at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...
# 4

No, I don't.

sandy_607a at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...
# 5

Tip: You will find the appropriate method in the Java API. (If you are not familiar whit that try http://java.sun.com/javase/6/docs/api/)

If you do not find the answer just ask again... Everybody loves to help here it seems. But you should know that the sooner you learn how to find the (simple or not simple) answers in the API the sooner you will be a real good java programmer. good luck!

Ja_Lava_Javaa at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...
# 6

Use .equals(). It's defined in Object, and subclassed by many classes. String's version of .equals() works to correctly check two Strings for equality. == and != do not.

paulcwa at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...
# 7

and if you want to see if a string doesn't equal something else use ! as in:

while (!myString1.equals(myString2))

{

.............

}

It's also useful to know about equalsIgnoreCase() which works as you'd expect it to.

petes1234a at 2007-7-29 14:15:55 > top of Java-index,Java Essentials,New To Java...