• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HELP

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

}
}
}
}
}
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic