You are viewing our Forum Archives. To view or take place in current topics click here.
Java Programing Problem Help required
Posted:

Java Programing Problem Help requiredPosted:

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]; //This is the method to create Arrays
char[]anstopicOne=new char[10];
char[]anstopicTwo=new char[10];
int Choice;







public void footballQuiz(){

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

public void ComputerQuiz(){

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




}
public void showMenu(){


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");

int Choice=Keyboard.readInt();

switch(Choice){

//case 1.enterDetails();break;
case 2:footballQuiz();break;//Creating Switch
//case 3.Show Results();break;
//case 4.Help();break;


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

}

}
while(Choice != 5);





}




}

----------------------------------------------------------------------------------------


public class Mainmenu {


public static void main (String args[]){
Quiz quizone=new Quiz();




quizone.showMenu();

}
}

-------------------------------------------------------------------------------------
So my problem currently is that the program wont stop showing after i press 5 which is exit it still keeps looping if anyone can spot or tell me any way to add the exit part

Note:I dont know if the IF loop would work because the school computer doesnt understand it thank you
#2. Posted:
Imp
  • Blind Luck
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
Your Do .. While loop is always excuting prior to checking the Choice Variable.

Change to a While(Choice!=5) with no Do, and the line above enter int Choice = 0;

So it looks like this


int Choice = 0;

while (Choice != 5) {

// YOUR CODE HERE

}


This will validate the variable before performing the code inside the while loop.

Another point I have to make, is that you need to check some of your answers!

World Cup is every 4 years...

No world cup was held in 2009, it was 2010 and was won by Spain!

And both RAM and ROM are physical memory, its just one is the Read Only part and the other is Random Access....

#3. Posted:
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
Dont Worry the Questions are most of them random stuff its the coding that counts not the questions tbh
#4. Posted:
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
Imp wrote Your Do .. While loop is always excuting prior to checking the Choice Variable.

Change to a While(Choice!=5) with no Do, and the line above enter int Choice = 0;

So it looks like this


int Choice = 0;


while (Choice != 5) {

// YOUR CODE HERE

}


This will validate the variable before performing the code inside the while loop.

Another point I have to make, is that you need to check some of your answers!

World Cup is every 4 years...

No world cup was held in 2009, it was 2010 and was won by Spain!

And both RAM and ROM are physical memory, its just one is the Read Only part and the other is Random Access....



Note:Did what you asked me now when i type 5 the program keeps running though it doesnt loop the script means the thing worked Thank you now if i maybe i mite be asking alot any guides on how to build a gui text box is just to unshowable thank you
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.