This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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