#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    NYC
    Posts
    11
    Rep Power
    0

    Smile Rookie needs some help


    Just starting out with Java. Working on an assignment and trying to create a menu. Hitting 1 will take you to 1 calculation, 2 another, and 3 exits you.

    Unless you hit 3 to exit 1 and 2 should loop when the calculation is concluded.

    I figure the option 1 and 2 calcs will be nested statements, so I'm trying to figure out how to put together the menu first and I hit a roadblock.

    Any help is appreciated.
    Here's what I have:

    import java.io.*;
    public class Earn {
    public static void main (String [] args) throws IOException{
    String input;
    BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));

    int menu=0;
    int hours;
    int earnings=0;

    do{

    System.out.println("*******************************************************");
    System.out.println(" MENU ");
    System.out.println("*******************************************************");
    System.out.println("1) Calculate earnings at $10 per hour");
    System.out.println("2) Calculate earnings at $0.10 doubled each hour");
    System.out.println("3) Exit");
    System.out.println("*******************************************************");


    System.out.println("Choose a menu option:");
    input= stdin.readLine();
    menu=Integer.parseInt(input);



    //option 1
    if(menu == 1);{
    System.out.println("How many hours?");
    input= stdin.readLine();
    hours=Integer.parseInt(input);

    earnings=(hours * 10);

    System.out.println("You will earn $" + earnings);
    }


    //option 2

    if(menu == 2);{
    System.out.println("How many hours?");
    input= stdin.readLine();
    hours=Integer.parseInt(input);

    }


    //option 3

    if(menu == 3);
    break;

    }while(menu != 3);


    }
    }

    Thanks for any input!
    Adam
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I'm sorry, I guess I don't understand what the problem is. Is this not working?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    NYC
    Posts
    11
    Rep Power
    0
    Basically just trying to make a menu to start my program.
    3 options, 3rd being exiting the program.
    If 1 or 2 are selected, they'll perform a calculation -- then it will start over again at the Menu.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    1
    Rep Power
    0
    Just quickly scanning through your code I saw some errors:
    -You have semicolons after the end-parenthesis in your if-statements, remove those.
    -You are not calculating and printing the earnings in menu option 2. (Maybe you just forgot it?)
    -Not really and error but you don't need to have an if-statement for option 3 since that is already checked in the while-statement.

IMN logo majestic logo threadwatch logo seochat tools logo