Re: Help with my program.
Hi and welcome to the forum.
Please see the announcements page for tips on forum use.
Can you paste the code on the forum rather than attach it. It is just easier for people to read that way, and please don't forget code tags.
Re: Help with my program.
Sorry here is my code:
import java.util.*;
import javax.swing.*;
class Quiz {
public static void main(String args[]){
String question[] = new String[10];//Declare Question Array
String ans[] = new String[10];// Declare Answer Array
int correct=0;//Declare correct for keeping count of correct answers
int incorrect=0;//Declare incorrect for keeping count of incorrect answers
String input;//Declare input for answers given by user
int n;//Declare n to be used as the random number below
Random r = new Random();//declaring r as a random number
question[0]= "Where is the Sea of Tranquillity?";//moon
question[1] = "Freddie Bulgara was better known as which lead singer?"; //freddie mercury
question[2] = "Robert Zimmerman is better known as whom in the music world?"; //bob dylan
question[3]= "How many teeth in a full adult set?";//32
question[4] = "Whose secretary was Miss Moneypenny?";//M
question[5] = "Who was the first person to reach the South Pole?"; //Roald Amundsen
question[6] = "The zloty is the currency of what country?";//Poland
question[7] = "What famous Australian landmark was opened in 1932?"; //Sydney Harbour Bridge
question[8] = "Siam is the former name for which country?";//Thailand
question[9] = "What do the letters DVD stand for?";//Digital Versatile Disk
ans[0]="Moon";
ans[1]="Freddie Mercury";
ans[2]="Bob Dylan";
ans[3]= "32";
ans[4]="M";
ans[5]="Roald Amundsen";
ans[6]="Poland";
ans[7]="Sydney Harbour Bridge";
ans[8]="Thailand";
ans[9]="Digital Versatile Disk";
for (int i =0; i<5; i++){
n=r.nextInt(10);//Declare n as the random number between 0-9
input=JOptionPane.showInputDialog(null, question[n]);
String input1= input.trim();//Trim answer
if(input1.equalsIgnoreCase(ans[n])){
correct++;
}
else {
JOptionPane.showMessageDialog(null, "Sorry that was incorrect\n The answer we were looking for was "+ans[n]);
incorrect++;
}
}
int output1=correct*20;//to work out correct percentage rate
//Output message pane showing results
JOptionPane.showMessageDialog(null, correct+ " right answers\n" +incorrect+ " incorrect answers\n " + output1+"% Success Rate ");
}
}