Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Can someone help me? I am writing an application in Java that displays a series of at least four survey questions.

Here is what I have so far:

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;
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;
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;
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;
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();
}
}
}

MODERATOR Edited: Added Markdown to the code so that it is readable in the Forums. Please refer to the Markdown CheatSheet for instructions on posting code in the Community :)

.

Thank you.

1 Answer

Thank you.