SHOW:
|
|
- or go back to the newest paste.
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 > value) | |
37 | { | |
38 | System.out.println("Your guess is too high. Guess again: "); | |
39 | too_high_Guess++; | |
40 | } | |
41 | else | |
42 | { | |
43 | System.out.println("Your guess is too low. Guess again: "); | |
44 | too_low_Guess++; | |
45 | } | |
46 | ||
47 | guess = input.nextInt(); | |
48 | ||
49 | } | |
50 | ||
51 | - | for(int total = 0; total == total_Guesses; total++) |
51 | + | |
52 | - | for(int low = 0; low < too_low_Guess; low++) |
52 | + | |
53 | - | for(int high = 0; high > too_high_Guess; high++) |
53 | + | |
54 | System.out.println("Your total number of guesses: " + total_Guesses); | |
55 | for(int totalcount = 1; totalcount <= total_Guesses; totalcount++) | |
56 | { | |
57 | System.out.printf("*"); | |
58 | } | |
59 | System.out.println(""); | |
60 | ||
61 | System.out.println("Your total number of low guesses: " +too_low_Guess); | |
62 | for(int lowcount = 1; lowcount <= too_low_Guess; lowcount++) | |
63 | { | |
64 | System.out.printf("*"); | |
65 | } | |
66 | System.out.println(""); | |
67 | ||
68 | System.out.println("Your total number of high guesses: " +too_high_Guess); | |
69 | for(int highcount = 1; highcount <= too_high_Guess; highcount++) | |
70 | { | |
71 | System.out.printf("*"); | |
72 | } | |
73 | ||
74 | if(too_high_Guess != 0) | |
75 | { | |
76 | System.out.println(""); | |
77 | } | |
78 | ||
79 | } | |
80 | } |