• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Orphaned case

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having trouble with a case in a switch. an error that says the case is orphaned keeps on ocurring. the code is:
// 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 option = 0;
final byte CALCULATE_PAY = 1;
final byte AUTHOR = 2;
final byte EXIT = 3;
//

while (option != 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 option: ");

//

option = Keyboard.readByte();

switch (option) {

//

case CALCULATE_PAY:{
double payRate;
double amtHours;
double over_time;
double amtGross;
double result;
double rate;

//

System.out.print("Hours worked: ");
result = payRate = Keyboard.readDouble();
//

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

// Start if statement
if (amtHours > 0 && payRate >= 5.15) {
if ( amtHours > 40) {
over_time = amtHours - 40;
payRate = (over_time * (1.5 * payRate)) + (payRate * amtHours);
}
else {
amtGross = amtHours * payRate;
}

// Display the final payrate
System.out.println("Gross Pay equals: "+(amtGross));
}
// Start second case for author information.
case AUTHOR: {

// display author information
System.out.println("Chris Buskulic");
break;
}

// Code the case exit option
case EXIT: {

// display an exit statement
System.out.println("Have a nice day");
break;

}

}
}
}
}
}


the AUTHOR case is the orphaned one
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know about "orphaned" but there's definitely a missing "}" character right before the AUTHOR case; the open one is right at the beginning of the previous case.
Note also that there's no "break" statement at the end of the first case; without it, execution will continue through onto the next ones. You have to use "break" to mark the end of every case, unless you specifically intend for then to flow together.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic