Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Default constructor generate two random equations
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Asim Aleem
Default constructor generate two random equations
0 Answer(s)      a year and 8 months ago
Posted in : Java Beginners


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());



    }
          }

Advertisement
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
java serializable default constructor
java serializable default constructor  java serializable default constructor
Advertisements
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
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
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 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
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... the randomGenerator.nextInt(num) method to generate the random number. The java.util.Random class
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
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
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
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
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. The Random class of java.util package can be used to generate a random
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
Java constructor
Java constructor  When does the compiler supply a default constructor for a class
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!  ...[] args){ int min = 115; int max = 250; Random random = new Random
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
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
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
Cramers rule for solving equations using java
Cramers rule for solving equations using java  My code: import... s=new Scanner(System.in); System.out.println("enter no of equations of matrix... double[N]; } System.out.println("enter the co-efficient of equations
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
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
Advertisements
 

 

 

DMCA.com