-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmid-term-S1
73 lines (67 loc) · 2.63 KB
/
mid-term-S1
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
import java.util.Scanner;
public class mid_term_S1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char answer; // get the answer option as char
int score = 0; // collect user score
int points = 5; // question points
// Question 1
System.out.println("Q1: What color is the sky?");
System.out.println("A)Green B)Blue C)Red D)Yellow");
for (int i = 0; i < 2; i++) {
System.out.print("Enter your answer (A, B, C, D): ");
answer = scanner.next().charAt(0);
if (answer == 'B' || answer == 'b') {
score += (i == 0) ? points : (points - 2);
System.out.println("Correct!");
break;
} else {
if (i == 1) {
System.out.println("Incorrect. The correct answer is B) Blue.");
} else {
System.out.println("Incorrect. Try again.");
}
}
}
points += 2;
// Question 2
System.out.println("\nQ2: How many legs does a cat have?");
System.out.println("A) 2 B) 3 C) 4 D) 6");
for (int i = 0; i < 2; i++) {
System.out.print("Enter your answer (A, B, C, D): ");
answer = scanner.next().charAt(0);
if (answer == 'C' || answer == 'c') {
score += (i == 0) ? points : (points - 2); // Deduct 2 points for the second attempt
System.out.println("Correct!");
break;
} else {
if (i == 1) {
System.out.println("Incorrect. The correct answer is C) 4.");
} else {
System.out.println("Incorrect. Try again.");
}
}
}
points += 2;
// Question 3
System.out.println("\nQ3: What is 2 + 2?");
System.out.println("A) 4 B) 3 C) 5 D) 5");
for (int i = 0; i < 2; i++) {
System.out.print("Enter your answer (A, B, C, D): ");
answer = scanner.next().charAt(0);
if (answer == 'A' || answer == 'a') {
score += (i == 0) ? points : (points - 2);
System.out.println("Correct!");
break;
} else {
if (i == 1) {
System.out.println("Incorrect. The correct answer is A) 4.");
} else {
System.out.println("Incorrect. Try again.");
}
}
}
System.out.println("\nYour final score is: " + score + " points.");
scanner.close();
}
}