- 1

I'm trying to create a quiz project on Java. The code seeems to be going fine. However, I want it to only take only String as an

public class Question { String prompt; String answer; public Question(String prompt, String answer) { this.prompt = prompt; this.answer = answer; } } import java.util.Scanner; public class App { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String q1 = "What is the hottest planet in the Solar System?\n" + "a. Mercury\nb. Venus\nc. Jupiter"; String q2 = "Who is the hottest instructor in the IT Department?\n" + "a. Sir Harly\nb. Sir Daryll\nc. Sir Rhady"; String q3 = "What is largest planet in the Solar System\n" + "a. Mercury\nb. Venus\nc. Jupiter"; String q4 = "What is the closest planet in the Sun?\n" + "a. Mercury\nb. Venus\nc. Jupiter"; String q5 = "What is the Earth's 'Twin Sister'?\n" + "a. Mercury\nb. Venus\nc. Jupiter"; String q6 = "Which among these three is a 'Gas Giant'?\n" + "a. Mercury\nb. Venus\nc. Jupiter"; String q7 = "What planet is Olympus Mons located?\n" + "a. Saturn\nb. Mars\nc. Uranus"; String q8 = "Which among these three planet doesn't have a ring?\n" + "a. Saturn\nb. Mars\nc. Uranus"; String q9 = "Which of these planet appears to spin on its side, orbiting the Sun like a rolling ball.?\n" + "a. Saturn\nb. Mars\nc. Uranus"; String q10 = "On which planet does the Great Red Spot, a long-lived enormous storm system, located?\n" + "a. Jupiter\nb. Mars\nc. Uranus"; Question [] questions = { new Question(q1, "b"), new Question(q2, "a"), new Question(q3, "c"), new Question(q4, "a"), new Question(q5, "b"), new Question(q6, "c"), new Question(q7, "b"), new Question(q8, "b"), new Question(q9, "c"), new Question(q10, "a") } ; takeTest(questions); } publ

21st Apr 2022, 2:17 PM
Reyven Legaspi
Reyven Legaspi - avatar
2 Answers
+ 1
Pls save the code and share link here.. This may help you, to share links 👇 https://www.sololearn.com/post/75089/?ref=app
21st Apr 2022, 2:41 PM
Jayakrishna 🇼🇳
0
I'm trying to create a quiz project on Java. The code seeems to be going fine. However, I want it to only take only String as an input and that if the user tries to enter anything other than a String, a message will pop-up that says they should enter a letter and let them try that item again. I am supposed to do a try-catch exception but if I input anything other than a String, InputMismatchException doesn't pop-up.
21st Apr 2022, 2:18 PM
Reyven Legaspi
Reyven Legaspi - avatar