Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: HiLo game in java

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face HiLo game in java

    Hello, iam quite new to this, i will try to explain what i want to code ,
    a HiLo game where the user can choose up to 3 different levels(1-10, 1-100, 1-1000)
    with these 3 methods

    public static void main(String[] args) {…}

    public static int playGame(int maxNumber) {...}

    public static void giveResponse(int answer, int guess) {…}
    with no Random , i will use the:

    int number = (int)(Math.random() * max) +1; to generate numbers

    I have tried so many times , but i don't get it ,

    my code so far

    import java.util.Scanner;
    public class HL{

    public static void main(String[] args ){

    Scanner s = new Scanner(System.in);

    System.out.println("Välkommen till HiLo!");
    System.out.println("Vilken svårighetsgrad?");
    System.out.println("1. Lätt (1-10)");
    System.out.println("2. Mellan (1-100)");
    System.out.println("3. Svårt (1-1000)");
    playGame(10);
    playGame(100);
    playGame(1000);


    } public static int playGame(int maxNumber){
    int guessCount=0;
    int max;
    int choice;
    int number=(int)(Math.random()*maxNumber)+1;

    Scanner s = new Scanner(System.in);

    choice=s.nextInt();
    if (choice == 1){
    System.out.println("Gissa på ett tal mellan 1-10");
    }else if(choice == 2) {
    System.out.println("Gissa på ett tal mellan 1-100");
    }else if(choice == 3) {
    System.out.println("Gissa på ett tal mellan 1-1000");

    while (guessCount > number){

    guessCount=s.nextInt();
    System.out.println("Gissningen var för låg");
    guessCount=s.nextInt();

    } if(guessCount < number) {
    guessCount=s.nextInt();
    System.out.println("Gissningen var för hög");


    }


    }

    return guessCount;

    }

    public static void giveResponse(int answer, int number){



    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: HiLo game in java

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    What problems are you having?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HiLo game in java

    import java.util.Scanner;
     public class HL{
     
       public static  void main(String[] args ){
     
          Scanner s = new Scanner(System.in);
     
          System.out.println("Välkommen till HiLo!");
          System.out.println("Choose level?");
          System.out.println("1. Easy (1-10)");
          System.out.println("2. Medium (1-100)");
          System.out.println("3. Hard (1-1000)");
          playGame(10);
          playGame(100);
          playGame(1000);
     
     
    }     public static int playGame(int maxNumber){
          int guessCount=0;
          int max;
          int choice;
          int number=(int)(Math.random()*maxNumber)+1;
     
          Scanner s = new Scanner(System.in);
     
          choice=s.nextInt();
          if (choice == 1){
           System.out.println("Guess a number between 1-10"); 
         }else if(choice == 2) {
             System.out.println("Guess a number between 1-100");
         }else if(choice == 3) {
             System.out.println("Guess a number between 1-1000");
     
         while (guessCount <= number){
               System.out.println("Guess was low");
             guessCount=s.nextInt();
     
     
          } if(guessCount >= number) {
           guessCount=s.nextInt();
          System.out.println("Guess was high");
          }  
                if(guess==number){
             counter=counter +1;
             System.out.println("Guess was correct "+counter+"try");
          }
     
              return guessCount;
     
    }
         public static void giveResponse(int answer, int guess){
         System.out.println&#8230;..
    }
     
     
     
    }
    Last edited by indytroll; April 25th, 2014 at 11:16 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: HiLo game in java

    Did you have any specific questions about the program?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Re: HiLo game in java

    Quote Originally Posted by Norm View Post
    Did you have any specific questions about the program?
    Hello, iam quite new to this, i will try to explain what i want to code ,
    a HiLo game where the user can choose up to 3 different levels(1-10, 1-100, 1-1000)
    with these 3 methods

    public static void main(String[] args) {…}

    public static int playGame(int maxNumber) {...}

    public static void giveResponse(int answer, int guess) {…}
    with no Random , i will use the:

    --- Update ---

    Quote Originally Posted by Norm View Post
    Did you have any specific questions about the program?
    Yes , i need to use 3 methods, the main , playGame and giveResponse, but i dont know how i use all the tree . The program stops after the user chooses level

    public static void main(String[] args) {…}

    public static int playGame(int maxNumber) {...}

    public static void giveResponse(int answer, int guess) {…}

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: HiLo game in java

    i need to use 3 methods,
    Can you explain what each method does and how and why the code would use them?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HiLo game in java

    Quote Originally Posted by Norm View Post
    Can you explain what each method does and how and why the code would use them?

    Yes, the first method is the main , i didnt have any problems there, the second method is public static int playGame(int maxNumber){
    } where the game will be, iam having problem with the last one there i want to have how low /high or correct
    public static void giveResponse(int answer, int guess){
    }
    i dont know how i can use all the 3 , i mean linking them.

Similar Threads

  1. java game
    By New2Programming in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 7th, 2014, 11:57 PM
  2. Game in Java
    By Freedom-Claw in forum Object Oriented Programming
    Replies: 2
    Last Post: March 27th, 2013, 04:50 PM
  3. Help with Snake Game Java Code: It's Impossible to Lose the Game
    By haruspex_icis in forum What's Wrong With My Code?
    Replies: 20
    Last Post: December 17th, 2012, 12:21 PM
  4. [SOLVED] Java Game
    By aman_chauhan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 3rd, 2012, 05:53 AM
  5. Need help for my java game
    By blunderblitz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2010, 06:32 AM

Tags for this Thread