X
Xano
Hello
I´ve made a quiz game and now I want to count the incorrect and the correct
answers, how can I do that?
Greetings
----------------------------------------------------------
import java.io.*;
import javax.swing.*;
public class Quiz
{
int i,j;
InputStreamReader reader;
BufferedReader buffer;
JTextArea txtarea;
// skapa referens till klassen Questions
//Questions myQuiz;
String choice;
String heading;
String p="\n\n Skriv (a) = konst, (b) = Geografi, (c) eller matematik (x)
avsluta:";
String answer,choice1;
String artsquestions;
String artsanswers;
String geoquestion;
String geoanswers;
/* dessa variabler innehåller antal korrekta och felaktiga
Arts och science frågor
*/
int
artCorrectAnswerCount,artWrongAnswerCount,geoCorrectanswerCount,geoWrongAnsw
erCount, mathcorrectanswercount,mathwronganswercount;
//Konstfrågor
String artsQuestions[] = {"Kan man se Mona Lisa i Paris? (enter t or f)",
"Pablo Picasso var svensk? (enter t or f)",
"Dans är en konstform? (enter t or f)",
"Zorn målade nakna flickor (enter t or f)",
"Van Gogh skar av sig tungan (enter t or f)"};
//Geografifrågor
final String geoQuestions[] = {"Talar man finska i Finland?(enter t or f)",
"USA ligger i sydamerika? (enter t or f)",
"Kairo är Egyptens huvudstad (enter t or f)",
"Palermo är en italiensk stad? (enter t or f)",
"Ligger Sahara öknen i Afrika? (enter t or f)"};
//Matematikfrågor
final String mathQuestions[] = {"11+2=24 (enter t or f)",
"6*7=42 (enter t or f)",
"2+2=4 (enter t or f)",
"2/2=1 (enter t or f)",
"0x0 =1 (enter t or f)"};
//Konstsvar
final String artsAnswers[]={"t","f","t","t","f"};
//Vetenskapsvar
final String geoAnswers[]={"t","f","t","t","t"};
//Matematiksvar
final String mathAnswers[]={"f","t","t","t","f"};
public static void main(String args[]) throws IOException // kastar IO
Exception
{
Quiz myQuiz =new Quiz();
myQuiz.gameQuestion();
String scienceQuestion;
//heading="\n"+"\t\t"+"************************************"+"\n"+
//!"\t\ skolprov...\n""************************************";
//System.out.println(heading);
}//main
public void gameQuestion()
{
choice = "";
do {
try {
//Instansierar en bufferedReader på System.in
reader=new InputStreamReader(System.in);
buffer=new BufferedReader(reader);
System.out.print(p);
choice=buffer.readLine();
if (choice.toLowerCase().equals("a"))
artsQuestions();
else if (choice.equals("b"))
geoQuestions();
else if (choice.equals("c"))
mathQuestions();
/*else if (choice.equals("x")) {
report();
break;**/
} catch(Exception e) {
System.out.println("Input error -- "+e.toString());
}//try
} while(true);// end of while
}// gameQuestion()
public void artsQuestions() throws IOException {
System.out.println("Valkommen till Skolprov-Konst");
System.out.println("Ta den tid du behover,\n\n Det finns fem fragor till
varje amne");
i = 0; artCorrectAnswerCount = 0; artWrongAnswerCount = 0;
String answer = "";
do{
System.out.print("Q."+(i+1) + " "+ artsQuestions);
//artsQuestions[] arrayen är definierad i Questions class
answer = buffer.readLine();
if ( answer.equals(artsAnswers)){
artCorrectAnswerCount++;
System.out.println(" Correct !!!");
} else {
artWrongAnswerCount++;
System.out.println(" Incorrect !!!");//blev Incorrect istället för Rätt,
tyckte det blev ful utskrift
}
i++;
if(i==5){
System.out.println("\n\n konstsektionen Slut ");
}
}while(i<5);// while loop
} //artsQuestions()
public void geoQuestions() throws IOException {
System.out.println("Valkommen till Skolprov-Vetenskap");
System.out.println("Ta den tid du behover,\n\n Det finns fem fragor till
varje amne");
int i = 0; int geoCorrectAnswerCount = 0;int geoWrongAnswerCount = 0;
String answer = "";
do{
System.out.print("Q."+(i+1) + " "+ geoQuestions);
//Användarens Indata
answer=buffer.readLine();
if ( answer.equals(geoAnswers)){
artCorrectAnswerCount++;
System.out.println(" Correct !!!");
}else{
artWrongAnswerCount++;
System.out.println(" Incorrect !!!");
}
i++;
if(i==5){
System.out.println("\n\n Geografisektionen Slut");
}
//}//while?
}while(i<5); //while
} //scienceQuestions()
public void mathQuestions() throws IOException {
System.out.println("Välkommen till Skolprov-Matematik");
System.out.println("Ta den tid du behover,\n\n Det finns fem fragor till
varje amne");
int i = 0,mathCorrectAnswerCount = 0,mathWrongAnswerCount = 0;
answer = "";
do{
System.out.print("Q."+(i+1) + " "+ mathQuestions);
//mathQuestions[] arrayen är definierad i Question class
//rätt svar eller fel svar
answer=buffer.readLine();
if ( answer.equals(mathAnswers)){
artCorrectAnswerCount++;
System.out.println(" Correct !!!");
} else {
artWrongAnswerCount++;
System.out.println(" Incorrect !!!");
}
i++;
if(i==5){
System.out.println("\n\n Matematiksektionen Slut");
}
}while(i<5);// while loop
}//mathQuestions()
//Hur kan vi skriva en metod report() som skriver ut rätt resp. fel svar per
kunskapsområde?
}//class Quiz
I´ve made a quiz game and now I want to count the incorrect and the correct
answers, how can I do that?
Greetings
----------------------------------------------------------
import java.io.*;
import javax.swing.*;
public class Quiz
{
int i,j;
InputStreamReader reader;
BufferedReader buffer;
JTextArea txtarea;
// skapa referens till klassen Questions
//Questions myQuiz;
String choice;
String heading;
String p="\n\n Skriv (a) = konst, (b) = Geografi, (c) eller matematik (x)
avsluta:";
String answer,choice1;
String artsquestions;
String artsanswers;
String geoquestion;
String geoanswers;
/* dessa variabler innehåller antal korrekta och felaktiga
Arts och science frågor
*/
int
artCorrectAnswerCount,artWrongAnswerCount,geoCorrectanswerCount,geoWrongAnsw
erCount, mathcorrectanswercount,mathwronganswercount;
//Konstfrågor
String artsQuestions[] = {"Kan man se Mona Lisa i Paris? (enter t or f)",
"Pablo Picasso var svensk? (enter t or f)",
"Dans är en konstform? (enter t or f)",
"Zorn målade nakna flickor (enter t or f)",
"Van Gogh skar av sig tungan (enter t or f)"};
//Geografifrågor
final String geoQuestions[] = {"Talar man finska i Finland?(enter t or f)",
"USA ligger i sydamerika? (enter t or f)",
"Kairo är Egyptens huvudstad (enter t or f)",
"Palermo är en italiensk stad? (enter t or f)",
"Ligger Sahara öknen i Afrika? (enter t or f)"};
//Matematikfrågor
final String mathQuestions[] = {"11+2=24 (enter t or f)",
"6*7=42 (enter t or f)",
"2+2=4 (enter t or f)",
"2/2=1 (enter t or f)",
"0x0 =1 (enter t or f)"};
//Konstsvar
final String artsAnswers[]={"t","f","t","t","f"};
//Vetenskapsvar
final String geoAnswers[]={"t","f","t","t","t"};
//Matematiksvar
final String mathAnswers[]={"f","t","t","t","f"};
public static void main(String args[]) throws IOException // kastar IO
Exception
{
Quiz myQuiz =new Quiz();
myQuiz.gameQuestion();
String scienceQuestion;
//heading="\n"+"\t\t"+"************************************"+"\n"+
//!"\t\ skolprov...\n""************************************";
//System.out.println(heading);
}//main
public void gameQuestion()
{
choice = "";
do {
try {
//Instansierar en bufferedReader på System.in
reader=new InputStreamReader(System.in);
buffer=new BufferedReader(reader);
System.out.print(p);
choice=buffer.readLine();
if (choice.toLowerCase().equals("a"))
artsQuestions();
else if (choice.equals("b"))
geoQuestions();
else if (choice.equals("c"))
mathQuestions();
/*else if (choice.equals("x")) {
report();
break;**/
} catch(Exception e) {
System.out.println("Input error -- "+e.toString());
}//try
} while(true);// end of while
}// gameQuestion()
public void artsQuestions() throws IOException {
System.out.println("Valkommen till Skolprov-Konst");
System.out.println("Ta den tid du behover,\n\n Det finns fem fragor till
varje amne");
i = 0; artCorrectAnswerCount = 0; artWrongAnswerCount = 0;
String answer = "";
do{
System.out.print("Q."+(i+1) + " "+ artsQuestions);
//artsQuestions[] arrayen är definierad i Questions class
answer = buffer.readLine();
if ( answer.equals(artsAnswers)){
artCorrectAnswerCount++;
System.out.println(" Correct !!!");
} else {
artWrongAnswerCount++;
System.out.println(" Incorrect !!!");//blev Incorrect istället för Rätt,
tyckte det blev ful utskrift
}
i++;
if(i==5){
System.out.println("\n\n konstsektionen Slut ");
}
}while(i<5);// while loop
} //artsQuestions()
public void geoQuestions() throws IOException {
System.out.println("Valkommen till Skolprov-Vetenskap");
System.out.println("Ta den tid du behover,\n\n Det finns fem fragor till
varje amne");
int i = 0; int geoCorrectAnswerCount = 0;int geoWrongAnswerCount = 0;
String answer = "";
do{
System.out.print("Q."+(i+1) + " "+ geoQuestions);
//Användarens Indata
answer=buffer.readLine();
if ( answer.equals(geoAnswers)){
artCorrectAnswerCount++;
System.out.println(" Correct !!!");
}else{
artWrongAnswerCount++;
System.out.println(" Incorrect !!!");
}
i++;
if(i==5){
System.out.println("\n\n Geografisektionen Slut");
}
//}//while?
}while(i<5); //while
} //scienceQuestions()
public void mathQuestions() throws IOException {
System.out.println("Välkommen till Skolprov-Matematik");
System.out.println("Ta den tid du behover,\n\n Det finns fem fragor till
varje amne");
int i = 0,mathCorrectAnswerCount = 0,mathWrongAnswerCount = 0;
answer = "";
do{
System.out.print("Q."+(i+1) + " "+ mathQuestions);
//mathQuestions[] arrayen är definierad i Question class
//rätt svar eller fel svar
answer=buffer.readLine();
if ( answer.equals(mathAnswers)){
artCorrectAnswerCount++;
System.out.println(" Correct !!!");
} else {
artWrongAnswerCount++;
System.out.println(" Incorrect !!!");
}
i++;
if(i==5){
System.out.println("\n\n Matematiksektionen Slut");
}
}while(i<5);// while loop
}//mathQuestions()
//Hur kan vi skriva en metod report() som skriver ut rätt resp. fel svar per
kunskapsområde?
}//class Quiz