Two Laptop Bag*
The moose likes Beginning Java and the fly likes HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HELP" Watch "HELP" New topic
Author

HELP

Chris Buskulic
Greenhorn

Joined: Sep 23, 2003
Posts: 5
Still getting orphaned cases and I have no Idea why. Please let me know if you see any other errors.

// Chris Buskulic
// This is a program that will be used to calculate an employee's
// pay for a week based on the amount
// of hours worked provided they are greater than 0.
// The application also calculates overtime pay which is
// based on the time and a half pay scale.
// The application also provides information on the author of the program.

//

public class App {
public static void main(String[] args) {

//
byte choice = 0;
final byte CALCULATE_PAY = 1;
final byte AUTHOR_INFORMATION = 2;
final byte EXIT = 3;

//

while (choice != EXIT) {

//

System.out.println("\t" + "Payroll Calculator");
Utility.skip();
System.out.println("1 - Calculate Pay");
System.out.println("2 - Author Information");
System.out.println("3 - Exit");
Utility.skip();
System.out.print("Enter your choice: ");

//

choice = Keyboard.readByte();

switch (choice) {
case CALCULATE_PAY:

double rate;
double amtHours;
double over_time;
double amtGross;
double result;


System.out.print("Hours worked: ");
result = rate = Keyboard.readDouble();
System.out.print("Hourly wage ($.$$): ");
rate = Keyboard.readDouble();

if (amtHours > 0 && rate >= 5.15) {
if ( amtHours > 40) {
over_time = amtHours - 40;
rate = (over_time * (1.5 * rate)) + (rate * amtHours);
}
else {
amtGross = amtHours * rate;
}
System.out.println("Gross Pay equals: " + (amtGross));
break;

case AUTHOR:
System.out.println("Chris Buskulic");
break;

case EXIT:
System.out.println("Have a nice day");
System.exit();
default:
System.out.println("\t" + "Error: invalid menue choice");
break;

}
}
}
}
}
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Chris:
A question: do you use a text editor that will automatically indent your code for you? If not (and I'm not being mean here, just helpful ), I suggest getting one. (Emacs will do this, any of the free IDEs (NetBeans, Eclipse, etc), will do this.) This feature is quite valuable for finding errors like this.
Also, please use the [CODE] and [/CODE] tags to paste formatted code here on the Ranch (like what follows)
[code]<font size="2">
// Chris Buskulic
// This is a program that will be used to calculate an employee's
// pay for a week based on the amount
// of hours worked provided they are greater than 0.
// The application also calculates overtime pay which is
// based on the time and a half pay scale.
// The application also provides information on the author of the program.

//

public class App {
public static void main(String[] args) {

//
byte choice = 0;
final byte CALCULATE_PAY = 1;
final byte AUTHOR_INFORMATION = 2;
final byte EXIT = 3;

//

while (choice != EXIT) {

//

System.out.println("\t" + "Payroll Calculator");
Utility.skip();
System.out.println("1 - Calculate Pay");
System.out.println("2 - Author Information");
System.out.println("3 - Exit");
Utility.skip();
System.out.print("Enter your choice: ");

//

choice = Keyboard.readByte();


switch (choice) {
case CALCULATE_PAY:

double rate;
double amtHours;
double over_time;
double amtGross;
double result;


System.out.print("Hours worked: ");
result = rate = Keyboard.readDouble();
System.out.print("Hourly wage ($.$$): ");
rate = Keyboard.readDouble();

if (amtHours > 0 && rate >= 5.15) {
if ( amtHours > 40) {
over_time = amtHours - 40;
rate = (over_time * (1.5 * rate)) + (rate * amtHours);
}
else {
amtGross = amtHours * rate;
}
System.out.println("Gross Pay equals: " + (amtGross));
break;

case AUTHOR:
System.out.println("Chris Buskulic");
break;

case EXIT:
System.out.println("Have a nice day");
System.exit();
default:
System.out.println("\t" + "Error: invalid menue choice");
break;

}
}
}
}
}
</font>[/code]
If you note, your case statements don't line up. One of them is in the switch block, but the other two are in the if block. You will need to close your if block, and then you shouldn't have these problems.
[ September 29, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP
 
Similar Threads
Alright, my eyes hurt from staring at this monitor trying to figure this out.
unreachable statement
orphaned case error on compile
DUE AT MIDNIGHT TONIGHT..1 ERROR..HELP
Orphaned case