Default constructor generate two random equations

Default constructor generate two random equations

Need to create a default constructor in a programmer defined class 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;




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

    }


    public String toString()
    {
        String str = new String(num1 + " " + operand + " " + num2);
        return str;
    }

}

However when I call it in the application class like I did underneath, I get 6-0 please help.

package project4;

    public class Project4App 
{
        public static void main(String[] args)
{
        Question question1 = new Question();
        System.out.println(question1.toString());



    }
          }
View Answers









Related Tutorials/Questions & Answers:
Default constructor generate two random equations
Default constructor generate two random equations  Need to create a default constructor in a programmer defined class that generates a random question, addition or subtraction. And when adding the numbers must be random from 0-12
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Advertisements
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
java serializable default constructor
java serializable default constructor  java serializable default constructor
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
java default constructor
be the default constructor: 1) public Student(){ private int rollNo = 0; private... the space in memory and initializes the fields. So, in the default constructor you can...java default constructor  suppose i hava a class: public class
program for default constructor in java
program for default constructor in java   class Box { double l; double b; double h; Box
Generate random numbers in Java
Generate random numbers in Java - How to use the java.util.Random class to generate desired random number in Java program? In this tutorial I will teach you... in Java which is used by developers to generate pseudo-random numbers in the Java
How do I generate random number?
How do I generate random number?  In my Java program there is a requirement of generating random numbers between two given numbers. How do I write..., The java.util.Random class can be used to generate the random numbers. Check the tutorial
How to generate a list of random numbers?
How to generate a list of random numbers?  Hi, How to generate a list of random numbers? I want code in scala programming language. Thanks  ... of Scala programming and it generates random integer. Following program
How to generate a list of random numbers?
How to generate a list of random numbers?  Hi, How to generate a list of random numbers? I want code in scala programming language. Thanks  ... of Scala programming and it generates random integer. Following program
How to generate a list of random numbers?
How to generate a list of random numbers?  Hi, How to generate a list of random numbers? I want code in scala programming language. Thanks  ... of Scala programming and it generates random integer. Following program
generate random numbers and display the largest
generate random numbers and display the largest  Hi, I am using... creates an array and fills it with random ints, prints the contents... ArrayRandom{ public static void main(String args[]){ Random r = new Random
generate random integer matrix in r
generate random integer matrix in r  Hi, I want to generate random integer matrix in r. What is easy code to generate random integer matrix in r? Thanks   Hi, Following is the code for generating random integer
ModuleNotFoundError: No module named 'random_string_generate'
ModuleNotFoundError: No module named 'random_string_generate'  Hi...: No module named 'random_string_generate' How to remove the ModuleNotFoundError: No module named 'random_string_generate' error? Thanks   Hi
ModuleNotFoundError: No module named 'random_string_generate'
ModuleNotFoundError: No module named 'random_string_generate'  Hi...: No module named 'random_string_generate' How to remove the ModuleNotFoundError: No module named 'random_string_generate' error? Thanks   Hi
Generate random numbers from 1 to 100
Generate random numbers from 1 to 100  1)A class Called: RandomNumberGenerator that generate random numbers from 1 to 100 2)A class Test that tests... an object from the Random NumberGenerator class to generate your input test data
how to generate random questions - Java Beginners
how to generate random questions  i am designing a test engine, i want my questions to be generated randomly. how can i do this?   Hi..."; Random generator = new Random(); int r = generator.nextInt(questionAr.length
How to generate random number in java
How to generate random number in java In this section you will learn how to generate random number in java. Java API  provide a random class in java.util.Random package which generate random number within a range. The random
Generate array of random numbers without repetition
Generate array of random numbers without repetition In the previous section, you have learnt how to generate an array of random numbers from the given array... created an application that will generate the array of random numbers without
constructor
: a call to a constructor method. Constructor methods are special methods... of that type. The new operator creates the object, the constructor initializes
Constructor
Constructor  what is the advantage of a constructor ? not the purpose of the constuctor? give me some in-depth analysis?   Please visit the following links: http://www.roseindia.net/java/java-tips/oop/constructors
J2ME Random Number
J2ME Random Number       In this application we are going to generate the random number using Random class. The Random class within the java.util package and we can use
Java constructor
Java constructor  When does the compiler supply a default constructor for a class
ModuleNotFoundError: No module named 'equations'
ModuleNotFoundError: No module named 'equations'  Hi, My Python... 'equations' How to remove the ModuleNotFoundError: No module named 'equations' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'equations'
ModuleNotFoundError: No module named 'equations'  Hi, My Python... 'equations' How to remove the ModuleNotFoundError: No module named 'equations' error? Thanks   Hi, In your python environment you
Generate shuffling in the specified list
list1 = Arrays.asList(employee); // create object of Random class to generate number randomly. Random num = new Random(); // shuffle and print the list according to the generated random number
Generating Random Number
for your application. Random Number is the frequently used to generate numbers... understand and use the code to generate random numbers in your java application.ADS_TO_REPLACE_1 The Random class of java.util package can be used to generate
Generate a documentation site for Maven project
In this section, you will learn to auto generate a documentation site with default design and pages for your Maven based project
using random number
using random number  generate a 10 digit number using random number and display the length of longest increasing series
MySQL random
MySQL random       In MySQL we can get the random records by using the method RAND() of MySQL. There are two versions of RAND() function : first RAND() and second is RAND(X
Version of com.kasonchan>equations-massbalance_2.11 dependency
List of Version of com.kasonchan>equations-massbalance_2.11 dependency
Version of com.kasonchan>equations-monooperation_2.11 dependency
List of Version of com.kasonchan>equations-monooperation_2.11 dependency
random numbers
random numbers  hi.. i am creating a website and on feedback form to authenticate user i want to generate a random number on label.if user types that number correctly in textbox then he is allowed to submit feedback otherwise
random number
random number   Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!  ... main(String[] args){ int min = 115; int max = 250; Random random
Generate array of random numbers
Generate array of random numbers You can generate a random number either by using the Random class or by using the static method Math.random() but it is better to use Random class. If you want to generate a series of random numbers
using random number
using random number  generate 10 number and display the length of longest incresing series
using random number
using random number  generate 10 digit number and display the length of longest incresing swries
Java Constructor
. A default constructor with no arguments will be called automatically by the Java... in the constructor. In the following example we have used two classes. First class we have...Every Class has at least one constructor, which assign initial values
Plotting equations on a cartesian Plane
Plotting equations on a cartesian Plane  Hey, Im sort of a beginner of java, and i at the moment of working on a program that takes the input of an equation (eg. y=3x) and plots possible values for it on a cartesian plane thats
call a constructor
call a constructor  How do you call a constructor for a parent class
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
ModuleNotFoundError: No module named 'python-category-equations'
ModuleNotFoundError: No module named 'python-category-equations'  Hi...: No module named 'python-category-equations' How to remove the ModuleNotFoundError: No module named 'python-category-equations' error? Thanks  
ModuleNotFoundError: No module named 'python-category-equations'
ModuleNotFoundError: No module named 'python-category-equations'  Hi...: No module named 'python-category-equations' How to remove the ModuleNotFoundError: No module named 'python-category-equations' error? Thanks  
ModuleNotFoundError: No module named 'python-domain-equations'
ModuleNotFoundError: No module named 'python-domain-equations'  Hi...: No module named 'python-domain-equations' How to remove the ModuleNotFoundError: No module named 'python-domain-equations' error? Thanks   
Constructor Overloading in Java
operator. A default constructor however is automatically called by the Java Virtual...; System.out.println("In Two Parameterized Constructor i and str1 are : "+i+"...= str3; this.k= k; System.out.println("In Two Parameterized Constructor str3

Ads