Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package project2;
  8.  
  9. /**
  10.  *
  11.  * @author gagikgarabigie
  12.  */
  13.  
  14. import java.util.Random; // loads in the library with the code to generate random numbers
  15. import java.util.Scanner; // asks user for input
  16.  
  17. public class GuessingGame
  18. {
  19.    
  20.     public static void main(String[] args)
  21.     {
  22.         Random rand = new Random(); // creates a new Random object with which to work
  23.         int value = rand.nextInt(35)+1; // this is the line of code that grabs the random number itself
  24.        
  25.         Scanner input = new Scanner(System.in);
  26.         System.out.println("Guess the number I'm thinking of, from 1-36: ");
  27.         int guess = input.nextInt();
  28.         int too_high_Guess = 0;
  29.         int too_low_Guess = 0;
  30.         int total_Guesses = 0;
  31.        
  32.        
  33.         while (value != guess)
  34.         {
  35.  
  36.             if(guess == -1)
  37.             {
  38.                 break;
  39.             }
  40.             if(guess > value)
  41.             {
  42.                 System.out.println("Your guess is too high. Guess again: ");
  43.                 too_high_Guess++;
  44.             }
  45.             else
  46.             {
  47.                 System.out.println("Your guess is too low. Guess again: ");
  48.                 too_low_Guess++;
  49.             }
  50.            
  51.             guess = input.nextInt();
  52.            
  53.         }
  54.        
  55.         if(guess == -1)
  56.         {
  57.             System.out.println("You've given up guessing. How sad.");
  58.         }
  59.         else
  60.         {
  61.             total_Guesses = too_high_Guess + too_low_Guess + 1;
  62.        
  63.             System.out.println("You've guessed correct!");
  64.             System.out.println("Your total number of guesses: " + total_Guesses);
  65.             for(int totalcount = 1; totalcount <= total_Guesses; totalcount++)
  66.             {
  67.                 System.out.printf("*");
  68.             }
  69.             System.out.printf("%n");
  70.        
  71.             System.out.println("Your total number of low guesses: " +too_low_Guess);
  72.             for(int lowcount = 1; lowcount <= too_low_Guess; lowcount++)
  73.             {
  74.                 System.out.printf("*");
  75.             }
  76.             System.out.printf("%n");
  77.        
  78.             System.out.println("Your total number of high guesses: " +too_high_Guess);
  79.             for(int highcount = 1; highcount <= too_high_Guess; highcount++)
  80.             {
  81.                 System.out.printf("*");
  82.             }
  83.        
  84.             if(too_high_Guess != 0)
  85.             {
  86.             System.out.printf("%n");
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement