forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomClue.java
99 lines (85 loc) · 2.91 KB
/
RandomClue.java
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
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* RandomClue.java : Your job is to ask your AssistantJack and get the correct
* answer in <= 20 tries. RandomClue is ONE solution to the problem,
* where a set of random numbers is generated every attempt until all three
* random numbers match the solution from the AssistantJack object.
*
* This is a sample solution, a driver using random number implementation.
* You can use this file as a guide to create your own SEPARATE driver for
* your implementation that can solve it in <= 20 times consistently.
*
* @author Nery Chapeton-Lamas (material from Kevin Lewis)
* @version 1.0
*
*/
import java.util.Random;
import java.util.Scanner;
public class RandomClue {
/*
* ALGORITHM:
*
* PROMPT "Which theory to test? (1, 2, 3[random]): "
* READ answerSet
* INSTANTIATE jack = new AssistantJack(answerSet)
* DO
* weapon = random int between 1 and 6
* location = random int between 1 and 10
* murder = random int between 1 and 6
* solution = jack.checkAnswer(weapon, location, murder)
* WHILE solution != 0
*
* OUTPUT "Total checks = " + jack.getTimesAsked()
* IF jack.getTimesAsked() is greater than 20 THEN
* OUTPUT "FAILED"
* ELSE
* OUTPUT "PASSED"
* END IF
*/
/**
* Driver method for random guessing approach
*
* @param args not used for driver
*/
public static void main() {
// DECLARATION + INITIALIZATION
int answerSet, solution, murder, weapon, location;
Theory answer;
AssistantJack jack;
Scanner keyboard = new Scanner(System.in);
Random random = new Random();
// INPUT
System.out.print("Which theory would like you like to test? (1, 2, 3[random]): ");
answerSet = keyboard.nextInt();
keyboard.close();
// PROCESSING
jack = new AssistantJack(answerSet);
//START OUR WEAPON LOCATION AND MURDER AT 1
int weapont = 1, locationt = 1, murdert = 1, total1 = 0;
//CHECK IF 1,1,1 IS CORRECT
solution = jack.checkAnswer(weapont, locationt, murdert);
//IF NOT CONTINUE WITH WHILE LOOP
while(solution != 0){
//SWITCH BASED OF WHAT JACK SAYS IS WRONG
switch(solution){
case 1:
weapont++;
break;
case 2:
locationt++;
break;
case 3:
murdert++;
break;
}
solution = jack.checkAnswer(weapont, locationt, murdert);
}
answer = new Theory(weapont, locationt, murdert);
// OUTPUT
System.out.println("Total Checks = " + jack.getTimesAsked() + ", Solution " + answer);
if (jack.getTimesAsked() > 20) {
System.out.println("FAILED!! You're a horrible Detective...¯\\_(ツ)_/¯");
} else {
System.out.println("WOW! You might as well be called Batman");
}
}
}