Write a java application that displays a series of at least four survey question
ID: 3780655 • Letter: W
Question
Write a java application that displays a series of at least four survey questions ; the survey can be on any social or political topic you like. Each questions should have two possible numeric-choice answers. At the end of the survey, use a dialog box to ask whether a user wants to (1) enter another set of responses to the same questions, or (2) quit. Continue to accept sets of responses until the user chooses to quit. Then display the results of the survey – for each question indicate how many users chose the first option or second option. Format the output in an order way which is user-friendly and is easy to digest.
Explanation / Answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ProblemQuiz {
private static int score = 0;
public static void start(){
int value;
BufferedReader bReader = new BufferedReader (new
InputStreamReader(System.in));
try {
System.out.println("Question N1: ");
System.out.println("Who starred as Rocky Balboa?");
System.out.println("1: Arnold Schwarzenegger 2: Sylvester Stallone");
System.out.println("3: Brad Pitt 4: Chuck Norris");
String data = bReader.readLine();
value = Integer.parseInt(data);
switch(value){
case 1:break;
case 2: score++;break;
case 3:break;
case 4:break;
default:break;
}
System.out.println("Question N2: ");
System.out.println("Who invented the television?");
System.out.println("1: John Logie Baird 2: Chuck Norris");
System.out.println("3: Louis Bleriot 4: Lady Chatterlys Lover");
data = bReader.readLine();
value = Integer.parseInt(data);
switch(value){
case 1:score++;break;
case 2:break;
case 3:break;
case 4:break;
default:break;
}
System.out.println("Question N3: ");
System.out.println("Who sang the theme song in 9 to 5?");
System.out.println("1: Victoria Cross 2: Louis Bleriot");
System.out.println("3: Walt Disney 4: Dolly Parton");
data = bReader.readLine();
value = Integer.parseInt(data);
switch(value){
case 1:break;
case 2:break;
case 3:break;
case 4:score++;break;
default:break;
}
System.out.println("Question N4: ");
System.out.println("Who did Michael Caine play in the Ipcress File?");
System.out.println("1: Chuck Norris 2: Harry Palmer");
System.out.println("3: John Constable 4: Oliver Hardy");
data = bReader.readLine();
value = Integer.parseInt(data);
switch(value){
case 1:break;
case 2:score++;break;
case 3:break;
case 4:break;
default:break;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args){
System.out.println("Welcome to Quiz!");
start();
System.out.println("Your score is: "+score);
System.out.println("1. Enter another set of responses to the same set of
questions");
System.out.println("2. Quit");
BufferedReader bReader = new BufferedReader (new
InputStreamReader(System.in));
String data;
try {
data = bReader.readLine();
int value = Integer.parseInt(data);
switch(value){
case 1:score=0;start();System.out.println("Your score is: "+score);break;
case 2:System.exit(1);
default:System.exit(1);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.