This repository was archived by the owner on Jul 23, 2019. It is now read-only.
forked from fenniless/BlueJ.TooLargeTooSmall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (51 loc) · 1.6 KB
/
Main.java
File metadata and controls
64 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Scanner;
public class Main
{
private int guessedNumber;
private int lastGuess;
private int correctNumber;
private boolean won;
public static void main(String[] args)
{
double mysteryNumber = 100*Math.random();
int correctNumber = (int)Math.floor(mysteryNumber);
System.out.println("Guess the mystery number between 0 and 100");
Scanner in = new Scanner(System.in);
int guess = in.nextInt();
int lastGuess = guess;
int totalGuesses = 1;
boolean firstMove = true;
while (guess != correctNumber) {
if (!firstMove && guess == lastGuess) {
System.out.println();
} else {
firstMove = false;
if (guess < correctNumber) {
System.out.println("Whoops, that's too small!");
} else {
System.out.println("Whoops, that's too big!");
}
System.out.println("Try again please: ");
}
lastGuess = guess;
guess = in.nextInt();
totalGuesses++;
}
System.out.println("Congratulations! That's the right number!");
System.out.printf("It took you %d guesses.\n", totalGuesses);
}
/**
* Start playing the TooLargeTooSmall game
*/
private void startGame()
{
// put your code here
return;
}
}