need help urgent - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need help urgent

rebelxdrebelxd Posts: 8Member
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

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • rebelxdrebelxd Posts: 8Member
    : : 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


  • zibadianzibadian Posts: 6,349Member
    : : : 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:
    [code]
    public class Menu {

    public void showMenu() {
    System.out.println("q: Quit");
    }

    public char getChoice() {
    char choice = '';
    String choices = "q";
    while (choices.indexOf(choice) == -1) {
    String s = System.console().readLine();
    if (s == null || s.length() == 0)
    choice = '';
    else {
    choice = s.charAt(0);
    if (choices.indexOf(choice) == -1) {
    System.out.println("Wrong choice. Try again");
    }
    }
    return choice;
    }

    }
    [/code]
    The rest is up to you.
Sign In or Register to comment.