Java Math Test

Multiplication/division math test that generates random values

Page 1 of 1

5 Replies - 3386 Views - Last Post: 17 October 2010 - 07:57 PM Rate Topic: -----

#1 blazelian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-October 10

Java Math Test

Posted 17 October 2010 - 03:17 PM

I am supposed to make a math test using drjava. The program first asks the user to enter "0" for division or "1" for multiplication. The program is then supposed to generate 2 random values and have the user answer the question.
The program should also keep track of how much correct answers there are and if there are more than sic then it should print congratulations
I am not exactly sure how to do this.
Please help as much as possible.

Is This A Good Question/Topic? 0
  • +

Replies To: Java Math Test

#2 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: Java Math Test

Posted 17 October 2010 - 03:21 PM

Which part don't you know how to do?

Random variables? Keep track of scores? Be a bit more specific please.

Also, post what you've done or at least your thought process.
Was This Post Helpful? 0
  • +
  • -

#3 blazelian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-October 10

Re: Java Math Test

Posted 17 October 2010 - 03:43 PM

im not sure how to do either
here is wat i have so far

import java.util.*;
import java.util.Random;

public class A2Q2  // The name of the algorithim

  {
  
  public static void main (String[] args)
  
  {
    
    Scanner keyboard = new Scanner( System.in );
    
    int ans;
    
    System.out.println ("Enter 0 for division and 1 for multiplication");
    
    x = keyboard.nextInt();
    
    System.out.println ( correct + "out of 10");
    
    ans = problemSolving(
      
  }
  
public static int problemSolving(int correct)
  
{
  
  int ans;
  
  boolean x;
  
  Random num1 = new Random();
  
  Random num2 = new Random();
  
  int randInt = r.nextInt(10);
  
  for (r = 0; r < 11 ; r++)
    
  {
    
    if (x = 0)
      
    {
      
      ans = num1 / num2;
    
    }
    
    else if (x = 1) 
    
    {
      
      ans = num1 * num2;
      
    }
  
  }
  
  return (ans);
  
}


Edited by Dogstopper: :code:

This post has been edited by Dogstopper: 17 October 2010 - 07:44 PM

Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2874
  • View blog
  • Posts: 11,047
  • Joined: 15-July 08

Re: Java Math Test

Posted 17 October 2010 - 07:47 PM

You have several compiling errors for missing things like end parentheses and semicolons. Check to make sure sure those all work. Then tell us what isn't working and the error message if applicable. Then, we will be able to help you better.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Java Math Test

Posted 17 October 2010 - 07:54 PM

you should pass x as parameter to the method
ans = problemSolving(
Was This Post Helpful? 0
  • +
  • -

#6 blazelian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-October 10

Re: Java Math Test

Posted 17 October 2010 - 07:57 PM

thank you very much
using this i was able to complete the code and have it working perfectly
thank you, again
its really appreciated
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1