Java

Moderators: zibadian
Number of threads: 7635
Number of posts: 17972

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Useful snippets for quiz style programs Posted by Pseudonym134 on 5 Dec 2009 at 8:27 AM
I've never used Java before today so I'm really clueless about the possibilities and such, I've made a really simple math quiz and I'm wondering if there is a better way to make it have more questions other than adding each one manually.

Is there anything that would let me massively condense the amount of code needed for say 30 questions, or any way to let the user input how many questions they want at the start and have that amount created?

I'm guessing that's what Arrays are used for, but I haven't really been able to find any easy to follow articles on using them - I learn alot better by seeing a practical example and changing it through trial and error.

Any help would be appreciated, below is what I have so far.


import java.io.*; 
import java.util.*;

class Test2 {
  public static void main (String[] args) throws IOException {

    BufferedReader Answer = new BufferedReader
      (new InputStreamReader(System.in));

    int num1, num2, correct1, correct2, score;

    int a = (int)(5.0 * Math.random()) + 5;
    int b = (int)(5.0 * Math.random()) + 5;
    int c = (int)(5.0 * Math.random()) + 5;
    int d = (int)(5.0 * Math.random()) + 5;

    System.out.print ("What is " +a+ " * " +b+ "? ");
    System.out.flush(); 
    num1 = Integer.parseInt( Answer.readLine());

if(num1 == a * b) 
      {
        correct1 = 1;
      }
      else{
         correct1 = 0;
      }
      	
    System.out.print ("What is " +c+ " * " +d+ "? ");
    System.out.flush(); 
    num2 = Integer.parseInt( Answer.readLine());

if(num2 == c * d) 
      {
	correct2 = 1;
      }
      else
      {
         correct2 = 0;
      }
  
    score = correct1 + correct2; 
    System.out.println("You scored " + score + " out of 2.");
 } 
} 
Report
Re: Useful snippets for quiz style programs Posted by wayne_zjw on 5 Dec 2009 at 9:20 AM
THANX VERY MUCH FOR THE SHARING!
GOOD LUCK 2 U
www.raqsoft.com
Report
Re: Useful snippets for quiz style programs Posted by Pseudonym134 on 5 Dec 2009 at 12:42 PM
o_O

Yeah I guess the subject was misleading lol, if you actually read what I posted you'd realise I was looking for help not offering it though.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.