Create a quiz using loops and/ or arrays. (not a print screen using an output bo
ID: 656710 • Letter: C
Question
Create a quiz using loops and/ or arrays. (not a print screen using an output box)
User will take a quiz that will determine what state they should live in.
The user will type in a number between 1 and 3 if they type anything else error message
They will be asked:
Do you want to live in Warm weather?
answers 1)yes 2) no 3) I don't want to live in too hot or too cold
Do you plan what activities do you want to be able to do?
answers 1)go to beach 2) skiing 3) I want to be able to do all both
What part of the country do you want to live in?
answers- 1)South 2)North 3)Mid
Results is mostly A-Florida B-New York C-North Carolina
one the quiz is over it will redirect you to a screen that will ask you
what state will you live in ?
what price range home do you want?
do you want to live in the city, suburbs, or country?
they will be shown a house based upon these answers
Explanation / Answer
i will give you a sample quiz solution.. hope this helps. though it uses gui..
import java.util.*;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Quiz2
{
public static int question;
public static int question2;
public static int question3;
public static int question4;
public static int question5;
public static String guess;
public static String guess2;
public static String guess3;
public static String guess4;
public static String guess5;
public static void main(String[] args)
{
//create a scanner object
Scanner sc = new Scanner(System.in);
JOptionPane.showMessageDialog(null, "Hi, This is my Quiz You will be asked a total of 5 questions in multiple choice format Please answer as A/B/C/D (Not case sensative)", "Introduction",
JOptionPane.INFORMATION_MESSAGE);
//Asks for a paricular item from the keyboard
guess = JOptionPane.showInputDialog(null, "1. Which of the following is not a bright colour? A. Cyan B. Green C. Black D. Yellow Answer: ", "Question 1",
JOptionPane.INFORMATION_MESSAGE);
//Asks for a paricular item from the keyboard
guess2 = JOptionPane.showInputDialog(null, "2. What genre does the singer John Legend sing in? A. Pop B. R&b C. Rap D. Rock Answer: ", "Question 2",
JOptionPane.INFORMATION_MESSAGE);
//Asks for a paricular item from the keyboard
guess3 = JOptionPane.showInputDialog(null, "3. What is the largest discovered Star in the Universe? A. The Sun B. VY Canis Majoris C. Eta Carinae D. Beetlejuice Answer: ", "Question 2",
JOptionPane.INFORMATION_MESSAGE);
//Asks for a paricular item from the keyboard
guess4 = JOptionPane.showInputDialog(null, "4. Who is Ronaldinho Gaucho? A. A famous Soccer player B. A famous Singer C. The founder of Microsoft D. A famous Actor Answer: ", "Question 2",
JOptionPane.INFORMATION_MESSAGE);
//Asks for a paricular item from the keyboard
guess5 = JOptionPane.showInputDialog(null, "5. Who is the actor who played the role as the terminator in the movie Last Action Hero? A. Arnold Schwarzenegger B. Adam Sandler C. Jean Claude Van Damme D. Sylvester Stallone Answer: ", "Question 2",
JOptionPane.INFORMATION_MESSAGE);
char x1 = guess.charAt(0);
char x2 = guess2.charAt(0);
char x3 = guess3.charAt(0);
char x4 = guess4.charAt(0);
char x5 = guess5.charAt(0);
switch (x1)
{
case 'a':
case 'A':
JOptionPane.showMessageDialog(null, "Incorrect! Cyan is a bright colour, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'b':
case 'B':
JOptionPane.showMessageDialog(null, "Incorrect! Green is a bright colour, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'c':
case 'C':
JOptionPane.showMessageDialog(null, "Correct! Black is not a bright colour", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'd':
case 'D':
JOptionPane.showMessageDialog(null, "Incorrect! Yellow is a bright colour, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
}
switch (x2)
{
case 'a':
case 'A':
JOptionPane.showMessageDialog(null, "Incorrect! John Legend is not a Pop Singer!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'b':
case 'B':
JOptionPane.showMessageDialog(null, "Correct! John Legend is a R&B Singer!", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'c':
case 'C':
JOptionPane.showMessageDialog(null, "Incorrect! John Legend does not Rap!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'd':
case 'D':
JOptionPane.showMessageDialog(null, "Incorrect! John Legend is not in the genre of Rock!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
}
switch (x3)
{
case 'a':
case 'A':
JOptionPane.showMessageDialog(null, "Incorrect! The Sun is the Biggest Star in our Solar System and not the Universe!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'b':
case 'B':
JOptionPane.showMessageDialog(null, "Correct! VY Canis Majoris is currently the Largest Star Discovered in the Universe!", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'c':
case 'C':
JOptionPane.showMessageDialog(null, "Incorrect! Eta Carinae is the Second Largest Star Discovered in the Universe!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'd':
case 'D':
JOptionPane.showMessageDialog(null, "Incorrect! Beetlejuice is the Third Largest Star Discovered in the Universe!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
}
switch (x4)
{
case 'a':
case 'A':
JOptionPane.showMessageDialog(null, "Correct! Ronaldinho Gaucho is a famous Soccer player!", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'b':
case 'B':
JOptionPane.showMessageDialog(null, "Incorrect! Ronaldinho Gaucho is not a Singer!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'c':
case 'C':
JOptionPane.showMessageDialog(null, "Incorrect! Bill Gates was the founder of Microsoft! NOT Ronaldinho Gaucho!!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'd':
case 'D':
JOptionPane.showMessageDialog(null, "Incorrect! Ronaldinho Gaucho is not an actor!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
}
switch (x5)
{
case 'a':
case 'A':
JOptionPane.showMessageDialog(null, "Incorrect! Arnold Schwarzenegger was the main actor of Last Action Hero, but in that same movie, who played the role as the terminator? Try Again!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'b':
case 'B':
JOptionPane.showMessageDialog(null, "Incorrect! No its not Adam Sandler, but it would be funny if it was!, Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'c':
case 'C':
JOptionPane.showMessageDialog(null, "Incorrect! It could have been Jean Claude Van Damme! But its not.... Please Try Again..", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
case 'd':
case 'D':
JOptionPane.showMessageDialog(null, "Correct! Sylvester Stallone played the role as the Terminator in the Movie Last Action Hero!", "Answer CHECK!",
JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.