You are viewing our Forum Archives. To view or take place in current topics click here.
Adding Score in Java
Posted:

Adding Score in JavaPosted:

CoD4Manicaz
  • New Member
Status: Offline
Joined: Feb 24, 201212Year Member
Posts: 23
Reputation Power: 1
Status: Offline
Joined: Feb 24, 201212Year Member
Posts: 23
Reputation Power: 1
public class Quiz {

String[]topicOne=new String[10];
String[]topicTwo=new String[10]; //These are the Properties.
char[]anstopicOne=new char[10];
char[]anstopicTwo=new char[10];

char userAnswer;
int Choice;
int c,f;
char Topic;
int Age;
String name;
String Surname;
String Adress;
int Telephone;
int Score;


public void footballQuiz(){

topicOne[0]="How many players are there in a football team.a. 11 b. 13 c .9 ";
anstopicOne[0]='a';
topicOne[1]="Every how many years is the world cup played.a.7.b.5.c.4";
anstopicOne[1]='b';
topicOne[2]="Who were the winners of the last champions league.a.Barcelona.b.Milan.c.Liverpool";
anstopicOne[2]='a';
topicOne[3]="Which player broke the record in the Barcelona book after 60 years.a.Sancez.b.Puyol.c.Messi";
anstopicOne[3]='c';
topicOne[4]="Which player was voted as best player of the year in 2011.a.Roney.b.Del Piero.c.Messi";//Football Questions
anstopicOne[4]='b';
topicOne[5]="Which team won the Serie A league in the year 2011.a.Inter.b.Juventus.c.Milan";
anstopicOne[5]='c';
topicOne[6]="Who won the Bira Moretti cup in the year 2008.a.Juventus.b.Inter.c.Napoli";
anstopicOne[6]='a';
topicOne[7]="Who was barcelonas top scorer in 2011.a.Xavi.b.Messi.c.Puyol.";
anstopicOne[7]='b';
topicOne[8]="Who won the Tim cup in the year 2011.a.Milan.b.Napoli.c.Inter";
anstopicOne[8]='c';
topicOne[9]="Who won the world cup in the year 2009.a.Italy.b.Brazil.c.England";
anstopicOne[9]='a';
}

public void ComputerQuiz(){

topicTwo[0]="What is the physical memory of a computer called.a.ram.b.rom";
anstopicTwo[0]='a';
topicTwo[1]="What is a graphics card cycle speed calculated with.a.Cpu.b.Gpu";
anstopicTwo[1]='b';
topicTwo[2]="Which is the fastest type of Ram.a.Dynamic Ram.b.Static Ram";
anstopicTwo[2]='a';
topicTwo[3]="What is one of the latest Malware Virus created in the world.a.spyware.b.keylogger";
anstopicTwo[3]='b';
topicTwo[4]="Which computer monitor is a power saving Monitor.a.3rd screen.b.Lcd Monitor";//Computer Questions
anstopicTwo[4]='b';
topicTwo[5]="What is the latest Creation of The corporation Microsoft.a.Windows 8.b.Bios";
anstopicTwo[5]='a';
topicTwo[6]="What is the Best computer in the world.a.Mainframe.b.Laptop";
anstopicTwo[6]='a';
topicTwo[7]="Which is the Type of virus that slows down your computer.a.spyware.b.Trojan horse";
anstopicTwo[7]='b';
topicTwo[8]="Who was the creator of the Apple mac Computer Corporation.a.Steve Jobs.b.Bill Gates";
anstopicTwo[8]='a';
topicTwo[9]="What was the first type of Operating System used by Computers.a.Bios.b.Windows Milenium";
anstopicTwo[9]='a';
}

public void help() {

System.out.println("Step One.Enter your details Age,Name and Surname(Age must be 18 or Higher)") ;
System.out.println(" Step Two.Pick a topic Between Football or Computer there will be 10 questions asked");//Help Instructions
System.out.println(" Step Three.Every question is 10 points test is out of 100 ");

}

public void exit(){

System.out.println("goodbye");//Exiting Message




}

public void pickTopic(){



System.out.println("Choose a topic");
System.out.println("Choose c For ComputerQuiz");
System.out.println("Choose f For FootballQuiz");

Topic=Keyboard.readChar();



if (Topic=='c')

showQuestions(); else



if (Topic=='f')


showQuestion();



else System.out.println("Invalid Entry");

}


public void enterDetails(){

System.out.println("name");
name=Keyboard.readString();

System.out.println("Surname");
Surname=Keyboard.readString();

System.out.println("Adress");
Adress=Keyboard.readString();

System.out.println("Telephone");
Telephone=Keyboard.readInt();

System.out.println("Age");
Age=Keyboard.readInt();

if (Age <= 18)
System.out.println("You may take the Quiz");

else System.out.println("You are to young to take the Quiz");


}

public void showDetails(){

enterDetails();

System.out.println(name);
System.out.println(Surname);
System.out.println(Adress);
System.out.println(Telephone);
System.out.println(Age);
System.out.println(Score);



}

public void showQuestions(){

ComputerQuiz();

for(c=0; c<10; c++){

System.out.println(topicTwo[c]);
System.out.println("Enter your answer");


userAnswer=Keyboard.readChar();
}
}

public void showQuestion(){
footballQuiz();


for(f=0;f<10; f++){

System.out.println(topicOne[f]);
System.out.println("Enter your answer");


userAnswer=Keyboard.readChar();

}

}



public void showResults(){


System.out.println(name);
System.out.println(Surname);
System.out.println(Adress);
System.out.println(Telephone);
System.out.println(Age);
System.out.println(Score);



}


public void showMenu(){

Choice = 0;


do{


System.out.println("1.enter details");

System.out.println("2.Choose a topic");//Menu Creation

System.out.println("3.Show Results");

System.out.println("4.Help");

System.out.println("5.Exit");







System.out.println("Enter a Choice");



Choice=Keyboard.readInt();


switch(Choice){




case 1:enterDetails();break;
case 2:pickTopic();break; //Creating Switch
case 3:showResults();break;
case 4:help();break;
case 5:exit();break;

default :System.out.println();break;

}

}


while(Choice != 5);



}




}
------------------------------------------------------------

how do i make the scores show in the show results menu and how do i make them count together
#2. Posted:
Experiment5X
  • TTG Senior
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
Woah woah woah, no one here is gonna look through all that code. Isolate your problem, and explain it better.
#3. Posted:
Imp
  • Retired Staff
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Its really not that difficult.

In the showQuestions and showQuestion reset the Score variable to 0

Score = 0;

Then after the userAnswer=Keyboard.readChar(); line in those 2 subroutines see if the answer is right and add 10 to the Score variable.

In showQuestions

if(userAnswer == anstopicTwo[c])
   Score = Score + 10;


In showQuestion

if(userAnswer == anstopicOne[f])
   Score = Score + 10;


You have already coded it to display your result
#4. Posted:
CoNdEmR
  • Retired Staff
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
In future please use the "code", "/code" tags(with brackets and not quotation marks).

Closed.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.