#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    [Project]Default constructor generate two random equations


    Need to create a default constructor that generates a random question, addition or subtraction. And when adding the numbers must be random from 0-12 and when subtracting the first number must be from 6-12, while the second is less than the first number. Here's my progress as of now:

    package project4;

    public class Question {
    private int num1;
    private int num2;
    private char operand;

    public Question()
    {
    operand = '+';
    num1 = (int)(Math.random())*12;
    num2 = (int)(Math.random())*12;
    int addition = num1 + num2;
    invalid = addition;


    operand = '-';
    num1 = ((int)(Math.random())*12+6);
    num2 = (int)(Math.random()) << num1;
    int subtraction = num1 - num2;
    negative = subtraction;
    }

    Also wanted to add when I call this via the toString method I get 6-0.
    Last edited by sunny9372; April 12th, 2013 at 06:19 PM. Reason: title not sufficient
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    Also posted at:
    http://www.javaprogrammingforums.com/whats-wrong-my-code/27605-default-constructor-generating-random-questions.html

IMN logo majestic logo threadwatch logo seochat tools logo