Results 1 to 11 of 11
  1. #1
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default New to Java and need help!!

    Im stuck on this problem and am up to this point. I dont really know what to do now. Help please!!


    System.out.println("Random Acts Main Menu");
    Scanner in = new Scanner(System.in);
    System.out.println("Please select one of the following (by typing the character): ");
    System.out.println("A - Circle Calculations");
    System.out.println("B - Print AND table for 3 variables");
    System.out.println("C - Vowel Removal Utility");
    System.out.println("Q - Quit");
    String choice = in.next();








    The Assignment
    You are to create a program that first prints a menu of selections that a user can pick from. The program
    then will accept the user’s selection. You then will use a switch statement to act on the user’s input.
    Once the selected task is complete the menu should print again and the program should accept input
    allowing the user to run another task or exit if they are done. If the user types in anything other than one
    of the menu options, print the message “Invalid choice, try again” and prompt user for input again.
    Here is an example menu that gets printed to the screen:


    Random Acts Main Menu
    Please select one of the following (by typing the character):
    A – Circle Calculations
    B – Print AND table for 3 variables
    C – Vowel Removal Utility
    Q – Quit
    I suggest you begin the assignment by constructing the menu while-loop first making the selection work. For each
    selection just print a line to screen so that you know that the selection is working. Then work on each of the parts
    (modules) of code

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default Re: New to Java and need help!!

    how would i structure a while statement for this without creating a duplicate variable?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: New to Java and need help!!

    I'd declare the String variable choice above the while loop, assigning it to an empty String "", and then use it inside of the while loop.

  5. #5
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default Re: New to Java and need help!!

    now im up to this point and still getting errors

    String choice = new String( );


    while (choice != Q) {
    System.out.println("Random Acts Main Menu");
    Scanner in = new Scanner(System.in);
    System.out.println("Please select one of the following (by typing the character): ");
    System.out.println("A - Circle Calculations");
    System.out.println("B - Print AND table for 3 variables");
    System.out.println("C - Vowel Removal Utility");
    System.out.println("Q - Quit");
    String choice = in.next();
    }

  6. #6
    synister1337 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: New to Java and need help!!

    Are you in Morehead's class? I've already mostly finished this assignment. A tip would be to make the choices simple numbers like 1, 2, 3, and 4. That way you don't have to deal with string comparisons and can use integers, which makes your switch statement easier.

  7. #7
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default Re: New to Java and need help!!

    Yea im in Moreheads. I thought we had to use the letters but making integers definitely makes it much easier

  8. #8
    synister1337 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: New to Java and need help!!

    I don't see any reason why we can't use integers. It's the same thing, just less complicated.

  9. #9
    bdl1127 is offline Member
    Join Date
    Jan 2012
    Posts
    26
    Rep Power
    0

    Default Re: New to Java and need help!!

    yea i switched to integers. im handicap when it comes to java. im at this point now and am still getting the cannot be resolved to a variable error.

    while (choice != 4) {
    System.out.println("Random Acts Main Menu");
    Scanner in = new Scanner(System.in);
    System.out.println("Please select one of the following (by typing the character): ");
    System.out.println("1 - Circle Calculations");
    System.out.println("2 - Print AND table for 3 variables");
    System.out.println("3 - Vowel Removal Utility");
    System.out.println("4 - Quit");
    int choice = in.nextInt();
    }

  10. #10
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default Re: New to Java and need help!!

    I think it's because in your loop test the first time around it's seeing if choice is not equal to 4, but choice doesn't exist yet(it's first declared IN the loop).

  11. #11
    bams is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: New to Java and need help!!

    Hope this helps :

    int choice = 0;
    System.out.println("Random Acts Main Menu");
    System.out.println("1 - Circle Calculations");
    System.out.println("2 - Print AND table for 3 variables");
    System.out.println("3 - Vowel Removal Utility");
    System.out.println("4 - Quit");
    do {
    System.out.print("Please select one of the above (by typing the character): ");
    Scanner in = new Scanner(System.in);
    choice = in.nextInt();
    }while (choice != 4);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •