nelson ruiz
Posts: 7
Nickname: nogal
Registered: Mar, 2008
|
|
Re: arrays and final outcome
|
Posted: Apr 6, 2008 8:55 PM
|
|
Hi Rajeev,
i did a couple of changes to the program but it is given me 2 errors and I don't get it
Quiz.java:114: <identifier> expected System.out.println("The number of correct answers is: " + correctCounter + ^ Quiz.java:114: illegal start of type System.out.println("The number of correct answers is: " + correctCounter + ^ 2 errors
Thanks
/* The purpose of this program is to write an application that contains an array of 10 multiple-choice quiz questions related to my favorite hobby. Each question contains three answer choices. Also create an array that holds the correct answer to each question (a, b, or c). Display ach question and verify that the user enters only a, b, or c as the answer, if not, keep prompting the user until a valid response is entered. if the user responds to a question correctly, display Correct!; otherwise display "The correct answer is" and the letter of the correct answer. After the user answer all the questions, display the number of correct and incorrect answers. */
import java.io.*;
public class Quiz { String [][] questionaire; int correctCounter =0; int incorrectCounter=0;
public static void main(String [ ] args) throws IOException { Quiz q = new Quiz(); }
public Quiz() throws IOException {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); String seekAnswer = null;
System.out.println("This is a 10 quiz program." + "\nLet's begin\n");
// crea un arreglo de dos dimensiones, para las preguntas // y las soluciones y lo rellena questionaire = new String[10][2]; questionaire[0][0] = "1. Which country is known as the roof of the world?" + "\na)Switzerland b)Argentina c)India\n"; questionaire[0][1] = "a"; questionaire[1][0] = "2. Which is the largest island in the world?" + "\na)Srilanka b)Australia c)Greenland\n"; questionaire[1][1] = "c"; questionaire[2][0] = "3. What is the study of curves in three-dimensional space, such as spheres or cones, called?" + "\na)Solid Geometry b)Space Geometry c)Abstract Geometry\n"; questionaire[2][1] = "a"; questionaire[3][0] = "4. Charles Darwin began his voyage on HMS Beagle from what port?" + "\na)Devonport, England b)Dover, France c)New York\n"; questionaire[3][1] = "a"; questionaire[4][0] = "5. The city of Manta is located in?" + "\na)Egypt b)France c)Ecuador\n"; questionaire[4][1] = "c"; questionaire[5][0] = "6. The longest highway in the world is?" + "\na)Trans-Canada b)Inter-State 90 USA c)E30 Route Europe\n"; questionaire[5][1] = "a"; questionaire[6][0] = "7. Which is the shallowest sea in the world?" + "\na)Caspian Sean b)Baltic Sea c)Sea of Azov\n"; questionaire[6][1] = "c"; questionaire[7][0] = "8. Which country is known as the lady of snow?" + "\na)Greenland b)Canada c)Pakistan\n"; questionaire[7][1] = "b"; questionaire[8][0] = "9. How many feathers are used to make badminton shuttle?" + "\na)10 to 12 b)18 to 20 c)14 to 16\n"; questionaire[8][1] = "c"; questionaire[9][0] = "10. Who developed the World Wide Web {www}?" + "\na)Tim Bernes Lee b)Charles Babbage c)Jim Osborne\n"; questionaire[9][1] = "a";
//Comprobar que el jugador escogio unicamente a,b o c for (int i = 0; i<10; i++) { do { System.out.println(questionaire[i][0]); seekAnswer = keyboard.readLine();
//Convierte la respuesta a minúsculas por si el usuario ha utilizado mayúsculas seekAnswer.toLowerCase(); if (seekAnswer.equals("a") || seekAnswer.equals("b") || seekAnswer.equals("c")) {
//Comprueba si la respuesta era correcta if( seekAnswer.equals(questionaire[i][1])) { System.out.println("Correct!\n"); correctCounter = correctCounter + 1; break; } else { System.out.println("The correct answer was: " + questionaire[i][1] + "\n"); incorrectCounter = incorrectCounter + 1; break; } } else { System.out.println("The answer must be: a), b) or c)"+ "\n"); } } while(true); }
}
//Muestra los resultados System.out.println("The number of correct answers is: " + correctCounter + "\nThe number of incorrect answers is: " + incorrectCounter); }
|
|