: : : Can ne1 help me on how to write a code for this program
: : :
: : :
: : : i have to make a launcher class which displays the menu
: : :
: : : Menu
: : : X) XXXXX
: : : X) XXXX
: : : X) XXXXX
: : : X) XXXXX
: : :
: : : x) quit
: : :
: : : then i have to create a method which displays the menu nd asks the
: : : user for a choice for example if user chooses quit program should
: : : terminate nd if user inputs an invalid choice it should tell them
: : : that it was an invalid choice
: : :
: : : Also after a game is completed it should ask the user if they want
: : : to play again.
: : :
: : : nd if they lose the game it should ask if they want to replay the
: : : same game
: : :
: : :
: : :
: : : so plz help me
: :
: : Start by defining a class and add a method to show the menu. This
: : should be simple enough, just a couple of System.out.println()'s.
: : The add a method to ask the user for a choice and validate if the
: : choice is within the choices of the menu. This requires a couple of
: : if-statements. This method should return the choice made.
: : Finally tie them together in a while-loop in a third method or in
: : the main() itself.
:
:
:
:
: hey man could u start me off..sorry i'm jst gettin used to java
:
:
:
Here are the two methods I talked about:
public class Menu {
public void showMenu() {
System.out.println("q: Quit");
}
public char getChoice() {
char choice = '\0';
String choices = "q";
while (choices.indexOf(choice) == -1) {
String s = System.console().readLine();
if (s == null || s.length() == 0)
choice = '\0';
else {
choice = s.charAt(0);
if (choices.indexOf(choice) == -1) {
System.out.println("Wrong choice. Try again");
}
}
return choice;
}
}
The rest is up to you.