Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP

 
Chris Buskulic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic