Skip to content

Commit 4bcc4d3

Browse files
committed
Create Quiz.kt
1 parent 109e8af commit 4bcc4d3

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

3-conditional-expressions/Quiz.kt

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
fun main() {
2+
val quizAnswer1 = 15
3+
var quizAnswer2 = 3
4+
val quizAnswer3 = "isosceles"
5+
val quizAnswer4 = 47
6+
7+
// Write your code below
8+
// Creating Quiz Questions
9+
10+
println("What is 75 / 5?: ")
11+
var studentAnswer1 = Integer.valueOf(readLine())
12+
13+
println("What is the value of y: 6 * 2y = 36")
14+
val studentAnswer2 = Integer.valueOf(readLine())
15+
16+
println("What is the name of a triangle that has two equal sides: ")
17+
val studentAnswer3 = readLine()
18+
19+
println("What is the value of 8 * 6 - (3 - 2): ")
20+
val studentAnswer4 = Integer.valueOf(readLine())
21+
22+
23+
// Grading the Quiz
24+
var points = 0
25+
// Question 1
26+
if(studentAnswer1 == quizAnswer1) {
27+
points += 25
28+
}
29+
30+
// Question 2
31+
if (studentAnswer2 == quizAnswer2) {
32+
points += 25
33+
} else if (studentAnswer2 == quizAnswer2++ || studentAnswer2 == quizAnswer2--) {
34+
points += 20
35+
println("The answer $studentAnswer2 is within 1 point of $quizAnswer2")
36+
} else {
37+
points += 1
38+
}
39+
40+
// Question 3
41+
if (studentAnswer3 == quizAnswer3) {
42+
points += 25
43+
} else if (studentAnswer3 == "equilateral") {
44+
points += 10
45+
} else {
46+
points += 1
47+
}
48+
49+
// Question 4
50+
if (studentAnswer4 == quizAnswer4) {
51+
points += 25
52+
} else if (studentAnswer4 in 44..54) {
53+
points += 20
54+
} else {
55+
points += 1
56+
}
57+
58+
59+
// Returning a Final Grade
60+
when (points) {
61+
in 0..59 -> println("$points points is an F.")
62+
in 60..69 -> println("$points points is a D.")
63+
in 70..79 -> println("$points points is a C.")
64+
in 80..89 -> println("$points points is a B.")
65+
in 90..99 -> println("$points points is an A.")
66+
in 100..110 -> println("$points points is an A+.")
67+
else -> println("Not a valid value.")
68+
}
69+
}

0 commit comments

Comments
 (0)