forked from sensei-thundercleese/closet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessNumber.java
More file actions
86 lines (65 loc) · 2.19 KB
/
Copy pathGuessNumber.java
File metadata and controls
86 lines (65 loc) · 2.19 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*==================================================
class GuessNumber -- fun fun fun!
eg, sample interaction with end user:
Guess a # fr 1-100: 50
Too high
Guess a # fr 1-49: 25
Too low
Guess a # fr 26-49: 38
Correct! It took 3 guesses
==================================================*/
/*==================================================
the Breakdown:
Blah blah blah, yakkity smakkity, and a nice tall glass of OJ...
==================================================*/
import cs1.Keyboard; /* must have cs1 dir in same dir as this file
for this to work */
public class GuessNumber {
//instance vars
private int _lo, _hi, _guessCtr, _target;
/*==================================================
constructor -- initializes a guess-a-number game
pre:
post: _lo is lower bound, _hi is upper bound,
_guessCtr is 1, _target is random int on range [_lo,_hi]
==================================================*/
public GuessNumber( int a, int b ) {
//*** YOUR IMPLEMENTATION HERE ***
}
/*==================================================
void playRec() -- Prompts a user to guess until guess is correct.
Uses recursion.
pre:
post:
==================================================*/
public void playRec() {
//*** YOUR IMPLEMENTATION HERE ***
}
/*==================================================
void playIter() -- Prompts a user to guess until guess is correct.
Uses iteration.
pre:
post:
==================================================*/
public void playIter() {
//*** YOUR IMPLEMENTATION HERE ***
}
//wrapper for playRec/playIter to simplify calling
public void play() {
//use one or the other below:
//playRec();
playIter();
}
//main method to run it all
public static void main( String[] args ) {
//instantiate a new game
GuessNumber g = new GuessNumber(1,100);
//start the game
g.play();
}
/*==================================================
_ _(_) --
pre:
post:
==================================================*/
}//end class