Skip to content

Commit 2d59f96

Browse files
committed
🔥 🔨 solved json manipulation quiz game
1 parent 5f7befe commit 2d59f96

File tree

11 files changed

+453
-21
lines changed

11 files changed

+453
-21
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gradle/
2+
.idea/
3+
gradlew
4+
gradlew.bat

LICENSE

-21
This file was deleted.

build.gradle

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'org.example'
6+
version '1.0-SNAPSHOT'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
14+
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
15+
}
4.05 KB
Binary file not shown.
+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
[
2+
{
3+
"Option a":"a.Unit Testing",
4+
"Option b":"b.Integration Testing",
5+
"question":"1.Which testing is done by developer?",
6+
"answer":"a",
7+
"Option c":"c.Sanity Testing",
8+
"Option d":"d.Regression Testing"
9+
},
10+
{
11+
"Option a":"a.Load Testing",
12+
"Option b":"b.Security Testing",
13+
"question":"2.Which is functional testing?",
14+
"answer":"c",
15+
"Option c":"c.Gorilla Testing",
16+
"Option d":"d.Benchmark Testing"
17+
},
18+
{
19+
"Option a":"a.Evaluating deliverable to find errors",
20+
"Option b":"b.Finding broken code",
21+
"question":"3.Which term is used to define testing?",
22+
"answer":"a",
23+
"Option c":"c.A stage of all projects",
24+
"Option d":"d.None of the above"
25+
},
26+
{
27+
"Option a":"a.Breadth test and depth test",
28+
"Option b":"b.Confirmation testing",
29+
"question":"4.Which methodology is used to performed Maintenance testing?",
30+
"answer":"a",
31+
"Option c":"c.Retesting",
32+
"Option d":"d.Sanity testing"
33+
},
34+
{
35+
"Option a":"a.Test Case",
36+
"Option b":"b.Requirements Traceability Matrix [RTM]",
37+
"question":"5.Which of the following is not part of the Test document?",
38+
"answer":"d",
39+
"Option c":"c.Test strategy",
40+
"Option d":"d.Project Initiation Note [PIN]"
41+
},
42+
{
43+
"Option a":"a.Testing Phase",
44+
"Option b":"b.Requirement Phase",
45+
"question":"6.Which of the following is not a valid phase of SDLC (Software Development Life Cycle)?",
46+
"answer":"d",
47+
"Option c":"c.Deployment phase",
48+
"Option d":"d.Testing closure"
49+
},
50+
{
51+
"Option a":"a.Structural testing",
52+
"Option b":"b.Error guessing technique",
53+
"question":"7.Which of the following testing is also known as white-box testing?",
54+
"answer":"a",
55+
"Option c":"c.Design based testing",
56+
"Option d":"d.None of the above"
57+
},
58+
{
59+
"Option a":"a.White box and black box testing",
60+
"Option b":"b.White-box testing",
61+
"question":"8.Which of the following testing is related to the boundary value analysis?",
62+
"answer":"c",
63+
"Option c":"c.Black box testing",
64+
"Option d":"d.None of the above"
65+
},
66+
{
67+
"Option a":"a.Test design technique",
68+
"Option b":"b.Test level",
69+
"question":"9.Functional testing is a ------?",
70+
"answer":"d",
71+
"Option c":"c.SDLC Model",
72+
"Option d":"d.Test type"
73+
},
74+
{
75+
"Option a":"a.Integration testing",
76+
"Option b":"b.Unit testing",
77+
"question":"10.What are the different levels of Testing?",
78+
"answer":"d",
79+
"Option c":"c.System testing",
80+
"Option d":"d.All of the above"
81+
},
82+
{
83+
"Option a":"a.Test type",
84+
"Option b":"b.Test Execution Level",
85+
"question":"11.Sanity testing is a ------",
86+
"answer":"b",
87+
"Option c":"c.Test Level",
88+
"Option d":"d.Test design technique"
89+
},
90+
{
91+
"Option a":"a.Statement coverage testing",
92+
"Option b":"b.Decision coverage testing",
93+
"question":"12.White box testing techniques are?",
94+
"answer":"d",
95+
"Option c":"c.Data flow testing",
96+
"Option d":"d.All of the above"
97+
},
98+
{
99+
"Option a":"a.User's end",
100+
"Option b":"b.Developer's end",
101+
"question":"13.In which environment we can performed the Alpha testing?",
102+
"answer":"b",
103+
"Option c":"c.User's and developer's end",
104+
"Option d":"d.None of the above"
105+
},
106+
{
107+
"Option a":"a.Schedule",
108+
"Option b":"b.Risk",
109+
"question":"14.Which of the below is not a part of the Test Plan?",
110+
"answer":"c",
111+
"Option c":"c.Incident reports",
112+
"Option d":"d.Entry and exit criteria"
113+
},
114+
{
115+
"Option a":"a.Design Errors",
116+
"Option b":"b.Interface Errors",
117+
"question":"15.What is the key objective of Integration testing?",
118+
"answer":"b",
119+
"Option c":"c.Procedure Errors",
120+
"Option d":"d.None of the mentioned"
121+
},
122+
{
123+
"Option a":"a.Experience-based Test Design Technique",
124+
"Option b":"b.White Box Test Design Technique",
125+
"question":"16.Exploratory testing is a -----?",
126+
"answer":"a",
127+
"Option c":"c.Black Box Test Design Technique",
128+
"Option d":"d.Grey Box Test Design Technique"
129+
},
130+
{
131+
"Option a":"a.After the software has been modified",
132+
"Option b":"b.As frequently as possible",
133+
"question":"17.What is the best time to perform Regression testing?",
134+
"answer":"d",
135+
"Option c":"c.When the environment has been modified",
136+
"Option d":"d.Both option a & c"
137+
},
138+
{
139+
"Option a":"a.Function testing",
140+
"Option b":"b.System testing",
141+
"question":"18.Which of the following is not part of the Test type?",
142+
"answer":"c",
143+
"Option c":"c.Statement testing",
144+
"Option d":"d.Database testing"
145+
},
146+
{
147+
"Option a":"a.Defect Report",
148+
"Option b":"b.Test Summary Report",
149+
"question":"19.Which Test Document is used to define the Exit Criteria of Testing?",
150+
"answer":"d",
151+
"Option c":"c.Test Case",
152+
"Option d":"d.Test Plan"
153+
},
154+
{
155+
"Option a":"a.Exit Criteria",
156+
"Option b":"b.How much regression testing should be done?",
157+
"question":"20.Which testing technique is used for usability testing?",
158+
"answer":"b",
159+
"Option c":"c.Different Tools to perform Regression Testing",
160+
"Option d":"d.How many more test cases need to write?"
161+
}
162+
]
885 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.jar

58.4 KB
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'JSONManipulation'
2+

src/main/java/QuizGame.java

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import org.json.simple.JSONArray;
2+
import org.json.simple.JSONObject;
3+
import org.json.simple.parser.JSONParser;
4+
import org.json.simple.parser.ParseException;
5+
6+
import java.io.FileReader;
7+
import java.io.FileWriter;
8+
import java.io.IOException;
9+
import java.util.Scanner;
10+
11+
public class QuizGame {
12+
public static void main(String[] args) throws IOException, ParseException {
13+
Scanner input = new Scanner(System.in);
14+
System.out.println("1.Add Quiz\n2.Start Quiz");
15+
System.out.print("Select one: ");
16+
int option = input.nextInt();
17+
18+
if (option == 1) {
19+
quizBank();
20+
21+
} else if (option == 2) {
22+
startQuiz();
23+
}
24+
}
25+
26+
private static void quizBank() throws IOException, ParseException, IOException, ParseException {
27+
char ch = 'y';
28+
String filePath = "./src/main/resources/QuestionBank.json";
29+
do {
30+
JSONParser jsonParser = new JSONParser();
31+
Object obj = jsonParser.parse(new FileReader(filePath));
32+
33+
Scanner input = new Scanner(System.in);
34+
System.out.println("Please add a ques here: ");
35+
JSONObject quesBank = new JSONObject();
36+
quesBank.put("question", input.nextLine());
37+
38+
System.out.println("Input options:");
39+
quesBank.put("Option a", input.nextLine());
40+
quesBank.put("Option b", input.nextLine());
41+
quesBank.put("Option c", input.nextLine());
42+
quesBank.put("Option d", input.nextLine());
43+
System.out.print("Please input the correct ans: ");
44+
quesBank.put("answer", input.next());
45+
46+
JSONArray quesBankArray = (JSONArray) obj;
47+
quesBankArray.add(quesBank);
48+
49+
FileWriter file = new FileWriter(filePath);
50+
file.write(quesBankArray.toJSONString());
51+
JSONArray quesBankString = quesBankArray;
52+
file.flush();
53+
file.close();
54+
System.out.print(quesBankArray);
55+
System.out.print(quesBankArray);
56+
System.out.println("\nDo you want to add more?[y/n]");
57+
ch = input.next().charAt(0);
58+
59+
}
60+
while (ch != 'n');
61+
}
62+
63+
public static void startQuiz() throws IOException, ParseException {
64+
int point = 0;
65+
66+
String filePath = "./src/main/resources/all_questions.json";
67+
68+
JSONParser jsonParser = new JSONParser();
69+
Object obj = jsonParser.parse(new FileReader(filePath));
70+
JSONArray quizArray = (JSONArray) obj;
71+
for (int i = 0; i < 5; i++) {
72+
int min = 1;
73+
int max = quizArray.size();
74+
int pos = (int) (Math.random() * (max - min + 1) + min);
75+
76+
JSONObject quizObject = (JSONObject) quizArray.get(pos);
77+
String name = (String) quizObject.get("question");
78+
String a = (String) quizObject.get("Option a");
79+
String b = (String) quizObject.get("Option b");
80+
String c = (String) quizObject.get("Option c");
81+
String d = (String) quizObject.get("Option d");
82+
System.out.println(name);
83+
System.out.println(a);
84+
System.out.println(b);
85+
System.out.println(c);
86+
System.out.println(d);
87+
88+
System.out.print("Give your answer: ");
89+
Scanner input = new Scanner(System.in);
90+
String givenAns = input.next();
91+
String ans = (String) quizObject.get("answer");
92+
93+
if (givenAns.equals(ans)) {
94+
System.out.println("Correct!");
95+
point++;
96+
} else {
97+
System.out.println("Not Correct!");
98+
}
99+
}
100+
System.out.println("Result: You got " + point + " out of 5");
101+
102+
}
103+
}

0 commit comments

Comments
 (0)