Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
need help urgent Posted by rebelxd on 15 May 2008 at 4:59 AM
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
Report
Re: need help urgent Posted by zibadian on 15 May 2008 at 12:51 PM
: 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.
Report
Re: need help urgent Posted by rebelxd on 17 May 2008 at 8:17 PM
: : 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


Report
Re: need help urgent Posted by zibadian on 17 May 2008 at 11:12 PM
: : : 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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.