Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class GuessingGame
- {
- private int upperBound;
- private int count, guess, num, pct;
- public GuessingGame(int stop)
- {
- upperBound = stop;
- }
- public void setNum(int stop)
- {
- upperBound = stop;
- }
- public void playGame()
- {
- int count = 0;
- Scanner keyboard = new Scanner(System.in);
- //upperBound = keyboard.nextInt();
- num = (int)(Math.random()*upperBound);
- guess = 0;
- System.out.println(num);
- do{
- out.println("Enter a number between 1 and " + upperBound);
- guess = keyboard.nextInt();
- count++;
- }while(guess != num);
- pct = (count/(count+1))*100;
- }
- @Override
- public String toString()
- {
- String output="";
- output = "It took you " + count + " tries to guess " + num + "\n you guessed wrong " + pct + "% of the time";
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement