-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.java
51 lines (45 loc) · 1.26 KB
/
Game.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
import java.util.Scanner;
class Game {
Scanner scanner = new Scanner(System.in);
RandomOps rgame = new RandomOps();
long StartTime = System.currentTimeMillis();
int score,falseAnswers;
/////
boolean timeOut() {
if((System.currentTimeMillis() - StartTime) / 1000 >=120)
return true;
else
return false;
}
public String gaming() {
while(!timeOut() ){
// System.out.println();//Go to new Line
String[] params = rgame.next();//get next operation with her answer
System.out.print(params[0]); //print operation
Integer answer;//for answer checking
do {//try to parse typed in keyboard
try {
answer = Integer.parseInt(scanner.nextLine() );
break;
}
catch(Exception e) {
System.out.println("Please type correct number! =_=");
}
}while(true);
if(params[1].equals(answer.toString())) {
score++;
// System.out.print(" OK");
}
else {
falseAnswers++;
System.out.println("Wrong");
}
}
System.out.println("Time Out!!!");
System.out.println("Thank you for your time");
String result = "Number of questions:\t" + (score + falseAnswers) +
"\nYour score:\t" + score +
"\nWrong answers:\t" + falseAnswers;
return result;
}
}