nogal07 de Abril del 2008
PreguntaHola,
Estoy haciendo un programa que contiene un arreglo de 10 que son preguntas de opcion multiple. Cada pregunta contiene 3 respuestas (a, b, c). Tambien debo crear un arreglo que contenga la respuesta correcta (a, b, c sin importar si es mayuscula o minuscula) para cada pregunta. Cuando la pregunta aparece en la pantalla, el usuario debe poner unicamente a, b, o c, sino lo hace, el juego no continua hasta que lo haga. Si la respuesta es correcta, aparecera un mensaje diciendo Correct!, de otra forma, el mensaje sera: The correct answer is a=Switzerland.\n" (como ejemplo para la primera pregunta). Al final de las 10 preguntas se debe desplegar un aviso diciendo cuantas correctas y cuantas incorrectas tuvo el jugador.
Lo inicie asi simle por que no estoy seguro de como trabaja la opcion javax.swing.OPtionPane con arreglos.
Inicie el programa, puse las preguntas en los arreglos (creo que bien), pero aun me falta la parte donde el jugador entra mayusculas o minusculas y no importa y lo otro es como hacer el conteo de las respuestas correctas e incorrectas.
Llevo dos semanas en este cuento y me siento limitado por mi poco conocimiento en java y en programacion (este es mi primer curso en programacion y en java). Cualquier ayuda se la agradeceria enormemente.
aqui puse el codigo que me presenta un error;
Quiz.java:8: cannot find symbol
symbol : variable a
location: class Quiz
String input=a, b, c;
^
1 error
[code]
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 seekResponse;
String seekAnswer = null;
System.out.println("This is a 10 quiz program."
+ "\nLet\'s begin");
String[ ] questionaire = new String[10];
questionaire[0] = "1. Which country is known as the roof of the
world?"
+ "\na)Switzerland b)Argentina c)India";
System.out.println(questionaire[0]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is a=Switzerland.\n");
}
questionaire[1] = "2. Which is the largest island in the world?"
+ "\na)Srilanka b)Australia c)Greenland";
System.out.println(questionaire[1]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=Greenland.\n");
}
questionaire[2] = "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";
System.out.println(questionaire[2]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is a=Solid
Geometry.\n");
}
questionaire[3] = "4. Charles Darwin began his voyage on HMS
Beagle from what port?"
+ "\na)Devonport, England b)Dover,
France c)New York";
System.out.println(questionaire[3]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct\n");
}
else
{
System.out.println("The correct answer is a=Devonport.\n");
}
questionaire[4] = "5. The city of Manta is located in?"
+ "\na)Egypt b)France c)Ecuador";
System.out.println(questionaire[4]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=Ecuador.\n");
}
questionaire[5] = "6. The longest highway in the world is?"
+ "\na)Trans-Canada b)Inter-State 90 USA c)E30 Route
Europe";
System.out.println(questionaire[5]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is
a=trans-Canada.\n");
}
questionaire[6] = "7. Which is the shallowest sea in the world?"
+ "\na)Caspian Sean b)Baltic Sea c)Sea of Azov";
System.out.println(questionaire[6]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=Sea of Azov.\n");
}
questionaire[7] = "8. Which country is known as the lady of snow?"
+ "\na)Greenland b)Canada c)Pakistan";
System.out.println(questionaire[7]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("b"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is b=Canada.\n");
}
questionaire[8] = "9. How many feathers are used to make
badminton shuttle?"
+ "\na)10 to 12 b)18 to 20 c)14 to 16";
System.out.println(questionaire[8]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=14 to 16.\n");
}
questionaire[9] = "10. Who developed the World Wide Web {www}?"
+ "\na)Tim Bernes Lee b)Charles Babbage c)Jim
Osborne";
System.out.println(questionaire[9]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is a=Tim Bernes
Lee.\n");
}
if (questionaire[9] == correct)
{
correctCounter = correctCounter + 1;
}
else
{
incorrectCounter = incorrectCounter + 1;
}
System.out.println("The number of correct answers is:"
+ correctCounter +"\nThe number of incorrect
answers is:"
+ incorrectCounter);
}
}
[/code]
Estoy haciendo un programa que contiene un arreglo de 10 que son preguntas de opcion multiple. Cada pregunta contiene 3 respuestas (a, b, c). Tambien debo crear un arreglo que contenga la respuesta correcta (a, b, c sin importar si es mayuscula o minuscula) para cada pregunta. Cuando la pregunta aparece en la pantalla, el usuario debe poner unicamente a, b, o c, sino lo hace, el juego no continua hasta que lo haga. Si la respuesta es correcta, aparecera un mensaje diciendo Correct!, de otra forma, el mensaje sera: The correct answer is a=Switzerland.\n" (como ejemplo para la primera pregunta). Al final de las 10 preguntas se debe desplegar un aviso diciendo cuantas correctas y cuantas incorrectas tuvo el jugador.
Lo inicie asi simle por que no estoy seguro de como trabaja la opcion javax.swing.OPtionPane con arreglos.
Inicie el programa, puse las preguntas en los arreglos (creo que bien), pero aun me falta la parte donde el jugador entra mayusculas o minusculas y no importa y lo otro es como hacer el conteo de las respuestas correctas e incorrectas.
Llevo dos semanas en este cuento y me siento limitado por mi poco conocimiento en java y en programacion (este es mi primer curso en programacion y en java). Cualquier ayuda se la agradeceria enormemente.
aqui puse el codigo que me presenta un error;
Quiz.java:8: cannot find symbol
symbol : variable a
location: class Quiz
String input=a, b, c;
^
1 error
[code]
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 seekResponse;
String seekAnswer = null;
System.out.println("This is a 10 quiz program."
+ "\nLet\'s begin");
String[ ] questionaire = new String[10];
questionaire[0] = "1. Which country is known as the roof of the
world?"
+ "\na)Switzerland b)Argentina c)India";
System.out.println(questionaire[0]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is a=Switzerland.\n");
}
questionaire[1] = "2. Which is the largest island in the world?"
+ "\na)Srilanka b)Australia c)Greenland";
System.out.println(questionaire[1]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=Greenland.\n");
}
questionaire[2] = "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";
System.out.println(questionaire[2]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is a=Solid
Geometry.\n");
}
questionaire[3] = "4. Charles Darwin began his voyage on HMS
Beagle from what port?"
+ "\na)Devonport, England b)Dover,
France c)New York";
System.out.println(questionaire[3]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct\n");
}
else
{
System.out.println("The correct answer is a=Devonport.\n");
}
questionaire[4] = "5. The city of Manta is located in?"
+ "\na)Egypt b)France c)Ecuador";
System.out.println(questionaire[4]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=Ecuador.\n");
}
questionaire[5] = "6. The longest highway in the world is?"
+ "\na)Trans-Canada b)Inter-State 90 USA c)E30 Route
Europe";
System.out.println(questionaire[5]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is
a=trans-Canada.\n");
}
questionaire[6] = "7. Which is the shallowest sea in the world?"
+ "\na)Caspian Sean b)Baltic Sea c)Sea of Azov";
System.out.println(questionaire[6]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=Sea of Azov.\n");
}
questionaire[7] = "8. Which country is known as the lady of snow?"
+ "\na)Greenland b)Canada c)Pakistan";
System.out.println(questionaire[7]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("b"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is b=Canada.\n");
}
questionaire[8] = "9. How many feathers are used to make
badminton shuttle?"
+ "\na)10 to 12 b)18 to 20 c)14 to 16";
System.out.println(questionaire[8]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("c"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is c=14 to 16.\n");
}
questionaire[9] = "10. Who developed the World Wide Web {www}?"
+ "\na)Tim Bernes Lee b)Charles Babbage c)Jim
Osborne";
System.out.println(questionaire[9]);
seekAnswer = keyboard.readLine();
if( seekAnswer.equals("a"))
{
System.out.println("\n Correct!\n");
}
else
{
System.out.println("The correct answer is a=Tim Bernes
Lee.\n");
}
if (questionaire[9] == correct)
{
correctCounter = correctCounter + 1;
}
else
{
incorrectCounter = incorrectCounter + 1;
}
System.out.println("The number of correct answers is:"
+ correctCounter +"\nThe number of incorrect
answers is:"
+ incorrectCounter);
}
}
[/code]
