Results 1 to 11 of 11
Thread: New to Java and need help!!
- 01-31-2012, 12:50 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
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
-
Re: New to Java and need help!!
What's your specific question?
- 01-31-2012, 12:54 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
Re: New to Java and need help!!
how would i structure a while statement for this without creating a duplicate variable?
-
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.
- 01-31-2012, 01:15 AM #5
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
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();
}
- 01-31-2012, 01:20 AM #6
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
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.
- 01-31-2012, 01:22 AM #7
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
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
- 01-31-2012, 01:24 AM #8
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
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.
- 01-31-2012, 01:40 AM #9
Member
- Join Date
- Jan 2012
- Posts
- 26
- Rep Power
- 0
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();
}
- 01-31-2012, 05:17 AM #10
Member
- Join Date
- Jan 2012
- Location
- The Coffee Pot
- Posts
- 36
- Rep Power
- 0
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).
- 01-31-2012, 07:27 AM #11
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
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);


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks