I wrote this simple multiply choice trivia quiz using Java programming language that shows how to use control statements, arrays, and methods in Java.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com
If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.
Your support on my channel is highly appreciated.
Thank you very much.
Program Listing
/**
* @author Jake Rodriguez Pomperada, MAED-IT, MIT
* jakerpomperada@gmail.com
* www.jakerpomperada.com / www.jakerpomperada.blogspot.com
* Bacolod City, Negros Occidental, Philippines
* January 25, 2021 Monday
*/
import java.util.Scanner;
public class Multiple_Choice_Quiz {
static Scanner Input = new Scanner(System.in);
public static void display_program() {
int correct = 0;
int incorrect=0;
int questions = 5;
System.out.print("\n");
System.out.println("Multiple Choice Trivia Quiz in Java");
System.out.print("\n");
String[][] Ques_Ans = {
{"What game was created by Markus Persson in the Java programming language?","\n A. Pacman \n B. Minecraft \n C. Starcraft \n D. Battle City\n","B"},
{"What nba team Lebron James wins his 4th Championship ring? ","\n A. Chicago Bulls \n B. New York Knicks \n C. LA Lakers \n D. Boston Celtics\n","C"},
{"Who is the present President of the Philippines? ","\n A. Gloria Arroyo \n B. Rody Duterte \n C. Fidel Ramos \n D. Noynoy Aquino\n","B"},
{"Who is the founder of Microsoft? ","\n A. Bill Allen \n B. Peter Norton \n C. Bill Gates \n D. Mark Cuban\n","C"},
{"What NBA Team Tim Duncan played?","\n A. San Antonio Spurs \n B. Toronto Raptors \n C. Detriot Piston \n D. Booklyn Nets\n","A"}};
String[] user_ans = new String[(int) questions];
int i=0;
do {
System.out.print("" + (i+1) + ". " + Ques_Ans[i][0] + " "+Ques_Ans[i][1]);
user_ans[i] = String.valueOf(Input.next().charAt(0));
if(Ques_Ans[i][2].equals(user_ans[i].toUpperCase())) {
System.out.println("\n Correct Answer!");
correct++;
}
else
{
System.out.println("\n Incorrect. The correct answer is "+Ques_Ans[i][2]);
incorrect++;
}
System.out.print("\n");
i++;
}while(i<questions);
System.out.print("\n");
System.out.print("\t===== DISPLAY RESULTS =====");
System.out.print("\n");
System.out.println("\n Number of correct answers: "+ correct);
System.out.println("\n Number of incorrect answers: "+ incorrect);
System.out.print("\n");
System.out.print("\tEnd of Program");
System.out.print("\n");
System.exit(0);
}
public static void main(String[] args){
display_program();
}
}
Hi sir can i ask how can i put a try and catch method and exception handling if the user will put special characters and blank answer? Thank you so much❤️❤️
ReplyDelete