-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmino_Acid_Quiz.java
More file actions
120 lines (100 loc) · 2.86 KB
/
Copy pathAmino_Acid_Quiz.java
File metadata and controls
120 lines (100 loc) · 2.86 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
package scratch;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
class Amino_Acid_Quiz
{
public static String[] FULL_NAMES =
{
"alanine","arginine", "asparagine",
"aspartic acid", "cysteine",
"glutamine", "glutamic acid",
"glycine" ,"histidine","isoleucine",
"leucine", "lysine", "methionine",
"phenylalanine", "proline",
"serine","threonine","tryptophan",
"tyrosine", "valine"
};
public static String[] SHORT_NAMES =
{ "A","R", "N", "D", "C", "Q", "E",
"G", "H", "I", "L", "K", "M", "F",
"P", "S", "T", "W", "Y", "V"
};
public static void main(String[] args)
{
//Declare temporary variables
String startString = " ";
Random rand = new Random();
int score = 0;
//Determine is the user wants to play
while(!(startString.equals("Y")))
{
System.out.println("Begin Amino Acid Quiz? (y/n)");
System.out.println("\n");
startString = System.console().readLine().toUpperCase();
}
//begin quiz
//start timer
long start = System.currentTimeMillis();
long finish = 0;
//track if the answer is correct
boolean correct = true;
boolean timeUp = false;
//variable used to receive random integers
int randPick = 0;
while ((correct == true) && (timeUp == false))
{
randPick = rand.nextInt(20);
System.out.println(FULL_NAMES[randPick]);
//start string is reused here for simplicity
startString = System.console().readLine().toUpperCase();
//check if answer is right
if (!(startString.equals(SHORT_NAMES[randPick])))
{
correct = false;
}
//check is time is up
//correct is reused for this purpose
finish = System.currentTimeMillis();
if ((finish - start) >= 30000)
{
timeUp = true;
}
//output message if answer was right
if (correct == true)
{
score++;
System.out.println("Correct");
System.out.println("Score: " + score);
float timeElapsed = finish - start;
timeElapsed = timeElapsed/1000;
System.out.println("Time: " + timeElapsed + " seconds");
System.out.println("\n");
}
else
{
System.out.println("Incorrect");
System.out.println("Correct answer: " + SHORT_NAMES[randPick]);
System.out.println("Score: " + score);
float timeElapsed = finish - start;
timeElapsed = timeElapsed/1000;
System.out.println("Time: " + timeElapsed + " seconds");
System.out.println("\n");
}
}
if (timeUp == true)
{
System.out.println("Time is up");
System.out.println("Correct answer: " + SHORT_NAMES[randPick]);
System.out.println("Score: " + score);
float timeElapsed = finish - start;
timeElapsed = timeElapsed/1000;
System.out.println("Time: " + timeElapsed + " seconds");
System.out.println("\n");
}
finish = System.currentTimeMillis();
float timeElapsed = finish - start;
System.out.println("Time Elapsed:");
System.out.println(timeElapsed/1000);
}
}