Project 3: Higher/Lower

Due: Thursday, June 16th 2005

 

 

For this assignment, you will be implementing a game of higher/lower. The computer will pick a random number between 1 and 100 (see provided code below.) The human player will then try to guess that number. For each guess, the computer will respond simply “higher” or “lower” if the number it has chosen is greater than or less than the guess respectively. The player should get 6 attempts to guess the number correctly. If the player hasn’t guessed correctly, the computer should reveal its number and the game is over.

 

 

Example Run:

 

Welcome to Higher/Lower!
Enter your name: Jon

I’ve chosen my number, Jon

Enter guess 1: 50

Higher

Enter guess 2: 75

Lower

Enter guess 3: 60

You guessed my number!

 

 

Provided Code:

 

class HigherLower {

     public static void main(String[] args) {

          int compNum = computerGuess();

          //Place your game code here

     }

 

     public static int computerGuess() {

          return (int)(Math.random()*100 )+ 1;

     }

}