Page 1 of 2 12 LastLast
Results 1 to 20 of 40
Like Tree2Likes

Thread: I Need Help With a Java Timer for a Quiz!

  1. #1
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Question I Need Help With a Java Timer for a Quiz!

    I have written a program which is a quiz that has 10 randomly generated multiplication questions. So far, it works fine. Before it is completed, I need to add in a timer which will record how long it takes for a user to answer the questions, and then to display that time at the end of the quiz. Please help! I will greatly appreciate it! :)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,767
    Blog Entries
    7
    Rep Power
    21

    Default Re: I Need Help With a Java Timer for a Quiz!

    Quote Originally Posted by JavaPr0grammer View Post
    I have written a program which is a quiz that has 10 randomly generated multiplication questions. So far, it works fine. Before it is completed, I need to add in a timer which will record how long it takes for a user to answer the questions, and then to display that time at the end of the quiz. Please help! I will greatly appreciate it! :)
    Get the current time at the start of the quiz:

    Java Code:
    long start= currentTimeMillis();
    and do the same at the end of the quiz:

    Java Code:
    long end= currentTimeMillis();
    You now know how many milli seconds it took the user to complete the entire quiz: (end-start).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    Thankyou so much! I will implement that right now :)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,767
    Blog Entries
    7
    Rep Power
    21

    Default Re: I Need Help With a Java Timer for a Quiz!

    Quote Originally Posted by JavaPr0grammer View Post
    Thankyou so much! I will implement that right now :)
    You're welcome of course; b.t.w. that method is a static method of the System class (I typed it incorrectly in my previous reply).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    It says I need to create a 'method'. Should I do this?I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-08-7.17.40-pm.png

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,767
    Blog Entries
    7
    Rep Power
    21

    Default Re: I Need Help With a Java Timer for a Quiz!

    No, see my previous reply (our replies must've crossed each other).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    I'm still having problems. Eclipse doesn't seem to recognise what I'm trying to do:

    I have created 'long' variables to store the data:
    I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-7.49.59-am.png

    But it still doesn't seem to work :(
    I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-7.50.07-am.png

    Thanks for all of the help :)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: I Need Help With a Java Timer for a Quiz!

    The method is static in the class: System. It should be coded:
    Java Code:
    long start = System.currentTimeMillis();  // save starting time
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    Thanks! Now I'm trying to add in the time at the end by doing (end - begin) to work out how long it has taken the user to answer the questions:
    I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-8.48.20-am.png
    It's still giving me errors. :(

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: I Need Help With a Java Timer for a Quiz!

    It's still giving me errors.
    Please copy the full text of the compiler's error message and paste it here. It has important info about the error.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-9.52.03-am.png

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: I Need Help With a Java Timer for a Quiz!

    Are those variables in scope where they are being used?
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    I think so. I have already declared them, and assigned the current time in milliseconds to each one (the 'begin' variable near the start of the program, and the 'end' variable near the end of the program). Here is a copy of the complete code, if you want to take a look:

    Java Code:
    package test;
    
    import java.util.Scanner;
    
    import javax.swing.JOptionPane;
    import java.util.Timer;
    
    public class Main {
    
    	public static void main(String [] args) {
    		
    		int score = 0;
    		
    		int loop1 = 0;
    		int loop2 = 0;
    		int loop3 = 0;
    		int loop4 = 0;
    		int loop5 = 0;
    		int loop6 = 0;
    		int loop7 = 0;
    		int loop8 = 0;
    		int loop9 = 0;
    		int loop10 = 0;
    		int loop11 = 0;
    		int Ran1 = (int)(Math.random() * (100-1));
    		int Ran2 = (int)(Math.random() * (100-1));
    		int Ran3 = (int)(Math.random() * (100-1));
    		int Ran4 = (int)(Math.random() * (100-1));
    		int Ran5 = (int)(Math.random() * (100-1));
    		int Ran6 = (int)(Math.random() * (100-1));
    		int Ran7 = (int)(Math.random() * (100-1));
    		int Ran8 = (int)(Math.random() * (100-1));
    		int Ran9 = (int)(Math.random() * (100-1));
    		int Ran10 = (int)(Math.random() * (100-1));
    		int Ran11 = (int)(Math.random() * (100-1));
    		int Ran12 = (int)(Math.random() * (100-1));
    		int Ran13 = (int)(Math.random() * (100-1));
    		int Ran14 = (int)(Math.random() * (100-1));
    		int Ran15 = (int)(Math.random() * (100-1));
    		int Ran16 = (int)(Math.random() * (100-1));
    		int Ran17 = (int)(Math.random() * (100-1));
    		int Ran18 = (int)(Math.random() * (100-1));
    		int Ran19 = (int)(Math.random() * (100-1));
    		int Ran20 = (int)(Math.random() * (100-1));
    		
    	String name = JOptionPane.showInputDialog(null, "What is your name? ");
    		while (loop1 < 100){
    			int start = JOptionPane.showConfirmDialog(null, "Hello " + name + ". Welcome to the Maths Quiz. Click YES when you are ready to begin.");
    			if(start == JOptionPane. YES_OPTION) {
    		break;
    	}
    	else{
    		System.exit(0);
    		break;
    	}
    	}
    		while (loop2 == 0){
    			// start timer here
    			long begin = System.currentTimeMillis();
    			String Q1 = JOptionPane.showInputDialog(null, "Question 1: " + Ran1 + " x " + Ran2);
    			if(Q1.equals("" + (Ran1 * Ran2) + "")) {
    			score += 1;
    			break;
    			}
    			else{
    			JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran1 * Ran2);
    			}
    			loop2++;
    			}
    			
    	while (loop3 == 0){
    		String Q2 = JOptionPane.showInputDialog(null, "Question 2: " + Ran3 + " x " + Ran4);
    		if(Q2.equals("" + (Ran3 * Ran4) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran3 * Ran4);
    		}
    		loop3++;
    		}
    	
    	while (loop4 == 0){
    		String Q3 = JOptionPane.showInputDialog(null, "Question 3: " + Ran5 + " x " + Ran6);
    		if(Q3.equals("" + (Ran5 * Ran6) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran5 * Ran6);
    		}
    		loop4++;
    		}
    	
    	while (loop5 == 0){
    		String Q4 = JOptionPane.showInputDialog(null, "Question 4: " + Ran7 + " x " + Ran8);
    		if(Q4.equals("" + (Ran7 * Ran8) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran7 * Ran8);
    		}
    		loop5++;
    		}
    	
    	while (loop6 == 0){
    		String Q5 = JOptionPane.showInputDialog(null, "Question 5: " + Ran9 + " x " + Ran10);
    		if(Q5.equals("" + (Ran9 * Ran10) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran9 * Ran10);
    		}
    		loop6++;
    		}
    	
    	while (loop7 == 0){
    		String Q6 = JOptionPane.showInputDialog(null, "Question 6: " + Ran11 + " x " + Ran12);
    		if(Q6.equals("" + (Ran11 * Ran12) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran11 * Ran12);
    		}
    		loop7++;
    		}
    	
    	while (loop8 == 0){
    		String Q7 = JOptionPane.showInputDialog(null, "Question 7: " + Ran13 + " x " + Ran14);
    		if(Q7.equals("" + (Ran13 * Ran14) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran13 * Ran14);
    		}
    		loop8++;
    		}
    	
    	while (loop9 == 0){
    		String Q8 = JOptionPane.showInputDialog(null, "Question 8: " + Ran15 + " x " + Ran16);
    		if(Q8.equals("" + (Ran15 * Ran16) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran15 * Ran16);
    		}
    		loop9++;
    		}
    	
    	while (loop10 == 0){
    		String Q9 = JOptionPane.showInputDialog(null, "Question 9: " + Ran17 + " x " + Ran18);
    		if(Q9.equals("" + (Ran17 * Ran18) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran17 * Ran18);
    		}
    		loop10++;
    		}
    	
    	while (loop11 == 0){
    		String Q10 = JOptionPane.showInputDialog(null, "Question 10: " + Ran19 + " x " + Ran20);
    		if(Q10.equals("" + (Ran19 * Ran20) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran19 * Ran20);
    		}
    		// stop timer here
    		long end = System.currentTimeMillis();
    		loop11++;
    		}
    		JOptionPane.showMessageDialog(null, "Congratulations " + name + "! You answered " + score + " questions correctly in" + (end - begin) + "seconds!");
    		}
    
    }
    Thanks :)

  14. #14
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    It looks like the end of the lines of code have been cut off for some reason. Here is a screenshot of the rest of line 180, where I am having errors:I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-10.21.51-am.png

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: I Need Help With a Java Timer for a Quiz!

    In scope means that the definition and usage of a variable are within the same pair of enclosing {}s.
    If a variable is local to a method or while loop, it is NOT known outside of the {} that enclose it.

    Move the definition for begin and end to the higher enclosing {}.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    But won't that change the results? I still want the time to be recorded just before the first question, and then just after the last question. If you like, you can show me: Here is the full version of the code:
    package test;

    import java.util.Scanner;

    import javax.swing.JOptionPane;
    import java.util.Timer;

    public class Main {

    public static void main(String [] args) {

    int score = 0;

    int loop1 = 0;
    int loop2 = 0;
    int loop3 = 0;
    int loop4 = 0;
    int loop5 = 0;
    int loop6 = 0;
    int loop7 = 0;
    int loop8 = 0;
    int loop9 = 0;
    int loop10 = 0;
    int loop11 = 0;
    int Ran1 = (int)(Math.random() * (100-1));
    int Ran2 = (int)(Math.random() * (100-1));
    int Ran3 = (int)(Math.random() * (100-1));
    int Ran4 = (int)(Math.random() * (100-1));
    int Ran5 = (int)(Math.random() * (100-1));
    int Ran6 = (int)(Math.random() * (100-1));
    int Ran7 = (int)(Math.random() * (100-1));
    int Ran8 = (int)(Math.random() * (100-1));
    int Ran9 = (int)(Math.random() * (100-1));
    int Ran10 = (int)(Math.random() * (100-1));
    int Ran11 = (int)(Math.random() * (100-1));
    int Ran12 = (int)(Math.random() * (100-1));
    int Ran13 = (int)(Math.random() * (100-1));
    int Ran14 = (int)(Math.random() * (100-1));
    int Ran15 = (int)(Math.random() * (100-1));
    int Ran16 = (int)(Math.random() * (100-1));
    int Ran17 = (int)(Math.random() * (100-1));
    int Ran18 = (int)(Math.random() * (100-1));
    int Ran19 = (int)(Math.random() * (100-1));
    int Ran20 = (int)(Math.random() * (100-1));

    String name = JOptionPane.showInputDialog(null, "What is your name? ");
    while (loop1 < 100){
    int start = JOptionPane.showConfirmDialog(null, "Hello " + name + ". Welcome to the Maths Quiz. Click YES when you are ready to begin.");
    if(start == JOptionPane. YES_OPTION) {
    break;
    }
    else{
    System.exit(0);
    break;
    }
    }
    while (loop2 == 0){
    // start timer here
    long begin = System.currentTimeMillis();
    String Q1 = JOptionPane.showInputDialog(null, "Question 1: " + Ran1 + " x " + Ran2);
    if(Q1.equals("" + (Ran1 * Ran2) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran1 * Ran2);
    }
    loop2++;
    }

    while (loop3 == 0){
    String Q2 = JOptionPane.showInputDialog(null, "Question 2: " + Ran3 + " x " + Ran4);
    if(Q2.equals("" + (Ran3 * Ran4) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran3 * Ran4);
    }
    loop3++;
    }

    while (loop4 == 0){
    String Q3 = JOptionPane.showInputDialog(null, "Question 3: " + Ran5 + " x " + Ran6);
    if(Q3.equals("" + (Ran5 * Ran6) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran5 * Ran6);
    }
    loop4++;
    }

    while (loop5 == 0){
    String Q4 = JOptionPane.showInputDialog(null, "Question 4: " + Ran7 + " x " + Ran8);
    if(Q4.equals("" + (Ran7 * Ran8) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran7 * Ran8);
    }
    loop5++;
    }

    while (loop6 == 0){
    String Q5 = JOptionPane.showInputDialog(null, "Question 5: " + Ran9 + " x " + Ran10);
    if(Q5.equals("" + (Ran9 * Ran10) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran9 * Ran10);
    }
    loop6++;
    }

    while (loop7 == 0){
    String Q6 = JOptionPane.showInputDialog(null, "Question 6: " + Ran11 + " x " + Ran12);
    if(Q6.equals("" + (Ran11 * Ran12) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran11 * Ran12);
    }
    loop7++;
    }

    while (loop8 == 0){
    String Q7 = JOptionPane.showInputDialog(null, "Question 7: " + Ran13 + " x " + Ran14);
    if(Q7.equals("" + (Ran13 * Ran14) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran13 * Ran14);
    }
    loop8++;
    }

    while (loop9 == 0){
    String Q8 = JOptionPane.showInputDialog(null, "Question 8: " + Ran15 + " x " + Ran16);
    if(Q8.equals("" + (Ran15 * Ran16) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran15 * Ran16);
    }
    loop9++;
    }

    while (loop10 == 0){
    String Q9 = JOptionPane.showInputDialog(null, "Question 9: " + Ran17 + " x " + Ran18);
    if(Q9.equals("" + (Ran17 * Ran18) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran17 * Ran18);
    }
    loop10++;
    }

    while (loop11 == 0){
    String Q10 = JOptionPane.showInputDialog(null, "Question 10: " + Ran19 + " x " + Ran20);
    if(Q10.equals("" + (Ran19 * Ran20) + "")) {
    score += 1;
    break;
    }
    else{
    JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran19 * Ran20);
    }
    // stop timer here
    long end = System.currentTimeMillis();
    loop11++;
    }
    JOptionPane.showMessageDialog(null, "Congratulations " + name + "! You answered " + score + " questions correctly in" + (end - begin) + "seconds!");
    }

    }

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: I Need Help With a Java Timer for a Quiz!

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Variables that are defined at a wider scope can be given values anywhere within there scopes.
    Define the variables at the widest scope and give them values as needed.
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    Java Code:
    package test;
    
    import java.util.Scanner;
    
    import javax.swing.JOptionPane;
    import java.util.Timer;
    
    public class Main {
    
    	public static void main(String [] args) {
    		
    		int score = 0;
    		
    		int loop1 = 0;
    		int loop2 = 0;
    		int loop3 = 0;
    		int loop4 = 0;
    		int loop5 = 0;
    		int loop6 = 0;
    		int loop7 = 0;
    		int loop8 = 0;
    		int loop9 = 0;
    		int loop10 = 0;
    		int loop11 = 0;
    		int Ran1 = (int)(Math.random() * (100-1));
    		int Ran2 = (int)(Math.random() * (100-1));
    		int Ran3 = (int)(Math.random() * (100-1));
    		int Ran4 = (int)(Math.random() * (100-1));
    		int Ran5 = (int)(Math.random() * (100-1));
    		int Ran6 = (int)(Math.random() * (100-1));
    		int Ran7 = (int)(Math.random() * (100-1));
    		int Ran8 = (int)(Math.random() * (100-1));
    		int Ran9 = (int)(Math.random() * (100-1));
    		int Ran10 = (int)(Math.random() * (100-1));
    		int Ran11 = (int)(Math.random() * (100-1));
    		int Ran12 = (int)(Math.random() * (100-1));
    		int Ran13 = (int)(Math.random() * (100-1));
    		int Ran14 = (int)(Math.random() * (100-1));
    		int Ran15 = (int)(Math.random() * (100-1));
    		int Ran16 = (int)(Math.random() * (100-1));
    		int Ran17 = (int)(Math.random() * (100-1));
    		int Ran18 = (int)(Math.random() * (100-1));
    		int Ran19 = (int)(Math.random() * (100-1));
    		int Ran20 = (int)(Math.random() * (100-1));
    		
    	String name = JOptionPane.showInputDialog(null, "What is your name? ");
    		while (loop1 < 100){
    			int start = JOptionPane.showConfirmDialog(null, "Hello " + name + ". Welcome to the Maths Quiz. Click YES when you are ready to begin.");
    			if(start == JOptionPane. YES_OPTION) {
    		break;
    	}
    	else{
    		System.exit(0);
    		break;
    	}
    	}
    		while (loop2 == 0){
    			// start timer here
    			long begin = System.currentTimeMillis();
    			String Q1 = JOptionPane.showInputDialog(null, "Question 1: " + Ran1 + " x " + Ran2);
    			if(Q1.equals("" + (Ran1 * Ran2) + "")) {
    			score += 1;
    			break;
    			}
    			else{
    			JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran1 * Ran2);
    			}
    			loop2++;
    			}
    			
    	while (loop3 == 0){
    		String Q2 = JOptionPane.showInputDialog(null, "Question 2: " + Ran3 + " x " + Ran4);
    		if(Q2.equals("" + (Ran3 * Ran4) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran3 * Ran4);
    		}
    		loop3++;
    		}
    	
    	while (loop4 == 0){
    		String Q3 = JOptionPane.showInputDialog(null, "Question 3: " + Ran5 + " x " + Ran6);
    		if(Q3.equals("" + (Ran5 * Ran6) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran5 * Ran6);
    		}
    		loop4++;
    		}
    	
    	while (loop5 == 0){
    		String Q4 = JOptionPane.showInputDialog(null, "Question 4: " + Ran7 + " x " + Ran8);
    		if(Q4.equals("" + (Ran7 * Ran8) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran7 * Ran8);
    		}
    		loop5++;
    		}
    	
    	while (loop6 == 0){
    		String Q5 = JOptionPane.showInputDialog(null, "Question 5: " + Ran9 + " x " + Ran10);
    		if(Q5.equals("" + (Ran9 * Ran10) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran9 * Ran10);
    		}
    		loop6++;
    		}
    	
    	while (loop7 == 0){
    		String Q6 = JOptionPane.showInputDialog(null, "Question 6: " + Ran11 + " x " + Ran12);
    		if(Q6.equals("" + (Ran11 * Ran12) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran11 * Ran12);
    		}
    		loop7++;
    		}
    	
    	while (loop8 == 0){
    		String Q7 = JOptionPane.showInputDialog(null, "Question 7: " + Ran13 + " x " + Ran14);
    		if(Q7.equals("" + (Ran13 * Ran14) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran13 * Ran14);
    		}
    		loop8++;
    		}
    	
    	while (loop9 == 0){
    		String Q8 = JOptionPane.showInputDialog(null, "Question 8: " + Ran15 + " x " + Ran16);
    		if(Q8.equals("" + (Ran15 * Ran16) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran15 * Ran16);
    		}
    		loop9++;
    		}
    	
    	while (loop10 == 0){
    		String Q9 = JOptionPane.showInputDialog(null, "Question 9: " + Ran17 + " x " + Ran18);
    		if(Q9.equals("" + (Ran17 * Ran18) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran17 * Ran18);
    		}
    		loop10++;
    		}
    	
    	while (loop11 == 0){
    		String Q10 = JOptionPane.showInputDialog(null, "Question 10: " + Ran19 + " x " + Ran20);
    		if(Q10.equals("" + (Ran19 * Ran20) + "")) {
    		score += 1;
    		break;
    		}
    		else{
    		JOptionPane.showMessageDialog(null, "That is not correct! The answer was " + Ran19 * Ran20);
    		}
    		// stop timer here
    		long end = System.currentTimeMillis();
    		loop11++;
    		}
    		JOptionPane.showMessageDialog(null, "Congratulations " + name + "! You answered " + score + " questions correctly in" + (end - begin) + "seconds!");
    		}
    
    }
    Attached Thumbnails Attached Thumbnails I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-10.21.51-am.png   I Need Help With a Java Timer for a Quiz!-screen-shot-2014-03-09-10.21.51-am.png  
    Last edited by JavaPr0grammer; 03-09-2014 at 04:16 AM.

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: I Need Help With a Java Timer for a Quiz!

    Is it working now?
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    Join Date
    Mar 2014
    Posts
    28
    Rep Power
    0

    Default Re: I Need Help With a Java Timer for a Quiz!

    Nope. It still says: 'Begin cannot be resolved to a variable' and 'end cannot be resolved to a variable.'

Page 1 of 2 12 LastLast

Similar Threads

  1. HELP - Java quiz application won't run
    By MD1993 in forum New To Java
    Replies: 4
    Last Post: 04-10-2012, 04:13 PM
  2. Please help with java quiz (should be easy to help)
    By karoloydi in forum New To Java
    Replies: 1
    Last Post: 11-29-2011, 03:59 AM
  3. JAVA Quiz
    By sara1988 in forum New To Java
    Replies: 4
    Last Post: 09-14-2011, 06:20 AM
  4. Swing java quiz
    By htuy in forum New To Java
    Replies: 7
    Last Post: 07-08-2011, 07:02 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •