| | |
Need help with Quiz code
![]() |
•
•
Join Date: Jul 2004
Posts: 2
Reputation:
Solved Threads: 0
Can someone help me to get this code to run. What am I missing. Any help is greatly appreciated.
import java.io.*;
public class Quiz
{
public static void main(String args[])
{
int correctCounter;
InputStreamReader reader;
BufferedReader buffer; keyboard = new
BufferedReader (new InputStreamReader (System.in));
}
String seekResponse;
System.out.println("Welcome to Hoffman School .. ");
{
// choose the subject
System.out.println("enter h for humanities, e for English or x for exit");
seekResponse = keyboard.readline();
if (seekResponse.equals ("h"); //do humanities quiz
{ System.out.println("The Declaration of Independence is the same as the
constitution");
seekResponse = keyboard.readline();
if (seekResponse=("t"));
System.out.println("incorrect answer");
if (seekResponse.equals ("f"));
System.out.println("correct");
System.out.println("At the Boston Tea Party the people threw coffee overboard");
if (seekResponse.equals ("t"));
System.out.println("incorrect answer");
If (seekResponse.equals ("f"));
System.out.println("correct");
}
else if (seekResponse.equals ("e"); //do English quiz
{System.out.println("A period goes at the end of a question");
seekResponse = keyboard.readline();
if (seekResponse.equals ("t"));
System.out.println("incorrect answerz");
if (seekResponse.equals ("f"));
System.out.println("correct");
System.out.println("Most sentences begin with a capital letter");
if (seekResponse.equals ("t"));
System.out.println("incorrect answer");
If (seekResponse.equals ("f"));
System.out.println("correct");
}
else if (seekResponse.equals ("x"));
exit// do exit logic
}
}
import java.io.*;
public class Quiz
{
public static void main(String args[])
{
int correctCounter;
InputStreamReader reader;
BufferedReader buffer; keyboard = new
BufferedReader (new InputStreamReader (System.in));
}
String seekResponse;
System.out.println("Welcome to Hoffman School .. ");
{
// choose the subject
System.out.println("enter h for humanities, e for English or x for exit");
seekResponse = keyboard.readline();
if (seekResponse.equals ("h"); //do humanities quiz
{ System.out.println("The Declaration of Independence is the same as the
constitution");
seekResponse = keyboard.readline();
if (seekResponse=("t"));
System.out.println("incorrect answer");
if (seekResponse.equals ("f"));
System.out.println("correct");
System.out.println("At the Boston Tea Party the people threw coffee overboard");
if (seekResponse.equals ("t"));
System.out.println("incorrect answer");
If (seekResponse.equals ("f"));
System.out.println("correct");
}
else if (seekResponse.equals ("e"); //do English quiz
{System.out.println("A period goes at the end of a question");
seekResponse = keyboard.readline();
if (seekResponse.equals ("t"));
System.out.println("incorrect answerz");
if (seekResponse.equals ("f"));
System.out.println("correct");
System.out.println("Most sentences begin with a capital letter");
if (seekResponse.equals ("t"));
System.out.println("incorrect answer");
If (seekResponse.equals ("f"));
System.out.println("correct");
}
else if (seekResponse.equals ("x"));
exit// do exit logic
}
}
Here's the modified code
You shouldn't put a ; at the end of EVERY line. like:
The other problem is that if you have more than one statment after an if, you need a curly bracket like this:
If you leave out the curly braces on that second example you will always print the second line, which wouldn't be the desired result.
Lastly, you had a capital I in an if statment. That won't work. Java is case sensitive.
Hope that helped.
Java Syntax (Toggle Plain Text)
import java.io.*; public class Quiz { public static void main(String args[]) { int correctCounter; InputStreamReader reader; BufferedReader buffer; keyboard = new BufferedReader (new InputStreamReader (System.in)); } String seekResponse; System.out.println("Welcome to Hoffman School .. ") { // choose the subject System.out.println("enter h for humanities, e for English or x for exit"); seekResponse = keyboard.readline(); if (seekResponse.equals ("h") //do humanities quiz { System.out.println("The Declaration of Independence is the same as the constitution"); seekResponse = keyboard.readline(); if (seekResponse=("t")) System.out.println("incorrect answer"); if (seekResponse.equals ("f")) System.out.println("correct"); System.out.println("At the Boston Tea Party the people threw coffee overboard"); if (seekResponse.equals ("t")) System.out.println("incorrect answer"); If (seekResponse.equals ("f")) System.out.println("correct"); } else if (seekResponse.equals ("e") //do English quiz { System.out.println("A period goes at the end of a question"); seekResponse = keyboard.readline(); if (seekResponse.equals ("t")) System.out.println("incorrect answerz"); if (seekResponse.equals ("f")) { System.out.println("correct"); System.out.println("Most sentences begin with a capital letter"); } if (seekResponse.equals ("t")) System.out.println("incorrect answer"); If (seekResponse.equals ("f")) System.out.println("correct"); } else if (seekResponse.equals ("x")) exit// do exit logic } } }
You shouldn't put a ; at the end of EVERY line. like:
Java Syntax (Toggle Plain Text)
if(1 > 2); // <-- that ; shouldn't be there
Java Syntax (Toggle Plain Text)
if(10 < 200) System.out.println("this is ok to do"); // That was ok if(10 < 200){ System.out.println("First Line"); System.out.println("Second Line"); }
Lastly, you had a capital I in an if statment. That won't work. Java is case sensitive.
Hope that helped.
![]() |
Similar Threads
- Javascript for an online quiz... (JavaScript / DHTML / AJAX)
- java code help 2;; (Java)
- Math Quiz Code (C)
- Please help with data file and array (C++)
Other Threads in the Java Forum
- Previous Thread: Error message when running simple Java pgm
- Next Thread: Need help with this email form
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class clear client code compile compiler component database development dice digit eclipse equation error event formatingtextintooltipjava fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login main map method methods mobile myregfun netbeans nonstatic notdisplaying pearl problem program programming project qt recursion repositories scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system thread threads tree variablebinding windows xor





