Need help with Quiz code

Reply

Join Date: Jul 2004
Posts: 2
Reputation: Vcrossley is an unknown quantity at this point 
Solved Threads: 0
Vcrossley Vcrossley is offline Offline
Newbie Poster

Need help with Quiz code

 
0
  #1
Aug 3rd, 2004
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
}
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 117
Reputation: Iron_Cross is an unknown quantity at this point 
Solved Threads: 2
Iron_Cross's Avatar
Iron_Cross Iron_Cross is offline Offline
Junior Poster

Re: Need help with Quiz code

 
0
  #2
Aug 4th, 2004
Here's the modified code
  1. import java.io.*;
  2. public class Quiz
  3. {
  4. public static void main(String args[])
  5. {
  6. int correctCounter;
  7. InputStreamReader reader;
  8. BufferedReader buffer;
  9. keyboard = new BufferedReader (new InputStreamReader (System.in));
  10. }
  11.  
  12. String seekResponse;
  13. System.out.println("Welcome to Hoffman School .. ")
  14. {
  15. // choose the subject
  16. System.out.println("enter h for humanities, e for English or x for exit");
  17. seekResponse = keyboard.readline();
  18. if (seekResponse.equals ("h") //do humanities quiz
  19. {
  20. System.out.println("The Declaration of Independence is the same as the constitution");
  21. seekResponse = keyboard.readline();
  22. if (seekResponse=("t"))
  23. System.out.println("incorrect answer");
  24. if (seekResponse.equals ("f"))
  25. System.out.println("correct");
  26. System.out.println("At the Boston Tea Party the people threw coffee overboard");
  27. if (seekResponse.equals ("t"))
  28. System.out.println("incorrect answer");
  29. If (seekResponse.equals ("f"))
  30. System.out.println("correct");
  31. }
  32. else if (seekResponse.equals ("e") //do English quiz
  33. {
  34. System.out.println("A period goes at the end of a question");
  35. seekResponse = keyboard.readline();
  36. if (seekResponse.equals ("t"))
  37. System.out.println("incorrect answerz");
  38. if (seekResponse.equals ("f"))
  39. {
  40. System.out.println("correct");
  41. System.out.println("Most sentences begin with a capital letter");
  42. }
  43. if (seekResponse.equals ("t"))
  44. System.out.println("incorrect answer");
  45. If (seekResponse.equals ("f"))
  46. System.out.println("correct");
  47. }
  48. else if (seekResponse.equals ("x"))
  49. exit// do exit logic
  50. }
  51. }
  52. }

You shouldn't put a ; at the end of EVERY line. like:
  1. if(1 > 2); // <-- that ; shouldn't be there
The other problem is that if you have more than one statment after an if, you need a curly bracket like this:
  1. if(10 < 200)
  2. System.out.println("this is ok to do");
  3. // That was ok
  4.  
  5. if(10 < 200){
  6. System.out.println("First Line");
  7. System.out.println("Second Line");
  8. }
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.
elitehackers.info
Today's Penny-Arcade!
Pain is weakness leaving the body!
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 2
Reputation: Vcrossley is an unknown quantity at this point 
Solved Threads: 0
Vcrossley Vcrossley is offline Offline
Newbie Poster

Re: Need help with Quiz code

 
0
  #3
Aug 4th, 2004
Thanks so much for your help. All I have to do now is add the counter to this.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC