-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputerAssistedInstructions.java
More file actions
154 lines (131 loc) · 4.14 KB
/
ComputerAssistedInstructions.java
File metadata and controls
154 lines (131 loc) · 4.14 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package computer.assisted.instructions;
import java.security.SecureRandom;
import java.util.Scanner;
public class ComputerAssistedInstructions {
private static final SecureRandom secure=new SecureRandom();
private static int a;
private static int b;
private static int prod =0;
private static int input;
//answer counters
private static int count;
private static int pos=0;
private static int difLev=0;
private static Scanner scan=new Scanner(System.in);
private static int z=0;
public static void main(String[] args) {
System.out.println("Enter your difficulty level btw 1and 5 ");
difLev=scan.nextInt();
difSelect();
}
//the generator method
public static void randGen(){
a=secure.nextInt(z);
b=secure.nextInt(z);
prod=a*b;
System.out.println("how much is "+a+" times "+b);
ansGen();
}
//answer checker
public static void ansGen(){
input=scan.nextInt();
//comparing answer
if(input!=prod){
System.out.println(negGen());
pos++;
count++;
if(count==10){
counter();
}
ansGen();
}else{
System.out.println(posRes());
count++;
if(count==10){
counter();
}
randGen();
}
//counter checker
}
public static void counter(){
int per=pos/10;
if(per>=7.5){
System.out.println("Congratulations, you are ready to go to the next level");
reset();
}else{
System.out.println("Please ask your teacher for extra help");
reset();
}
}
//positive response selector
public static String posRes(){
String restype=" ";
int res=1+secure.nextInt(4);
switch(res){
case(1):
restype="Very good";
break;
case(2):
restype="Excellent!";
break;
case(3):
restype="Nice Work!";
break;
case(4):
restype="Keep up the good work!";
break;
}
return restype;
}
//negative response generator
public static String negGen(){
String restype=" ";
int res=1+secure.nextInt(4);
switch(res){
case(1):
restype="No. Please try again.";
break;
case(2):
restype="Wrong. Try once more";
break;
case(3):
restype="Don't give up";
break;
case(4):
restype="No. Keep trying.";
break;
}
return restype;
}
public static void reset(){
count=0;
pos=0;
randGen();
}
public static void difSelect(){
int z=0;
switch(difLev){
case(1):
z=10;
break;
case(2):
z=100;
break;
case(3):
z=1000;
break;
case(4):
z=10000;
case(5):
z=100000;
break;
}
randGen();
}
}