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



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

Have Programming Question? Ask it here!
 
 
 


Asim Aleem
Default constructor generate two random equations
0 Answer(s)      a year and 3 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
Random Numbers - shuffling
is described at the bottom. Shuffling: Random numbers without replacement The random number methods generate numbers with replacement. This means that a particular random number may be generated repeatedly. If you don't want the same
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
Random numbers - Introduction
. Type, Range, and Distribution When you generate random numbers, you need to decide... generate a random number? Computers are deterministic -- they do the same thing... for a computer to compute a truly random number. But the methods that are used generate
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
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
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
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
getting random number in java
to generate the random number in Java Thanks in Advance...getting random number in java  getting random number in java Hi everyone, i am trying to get a random number in a particular range. for example
random number
random number  Sir could u please send me the code registration form of roseindia.net with image varification
PHP Random Number
PHP Generate Random Numbers: A random number is becoming more useful.... To generate random number, PHP provides rand() function. ...;?php echo "<b>rand() function will generate a random
call a constructor
call a constructor  How do you call a constructor for a parent class
constructor in servlet
constructor in servlet  Can we use the constructor, instead of init... the constructor instead of init(). There's nothing to stop you. But you shouldn't... your no-arg constructor. So you won't have access to a ServletConfig
Constructor in Servlet.
Constructor in Servlet.  how to write a constructor in Java Servlet?   Servlet is like a POJO .You can create constructor in servlet. You can also use constructor for initialising purpose but it is not a useful approach
constructor inheritance
constructor inheritance  can we inherit constructor ?if not then why yhis example is given class A { public A() { System.out.println("In A ctor"); } } class B extends
constructor or object
constructor or object  object or construct which create first?   A constructor is always created first. Here is an example: class Example { Example(String st){ System.out.println(st); } public
using constructor
using constructor  all constructor for matrix class?   The given code implements the Matrix class and show the addition of two matrices...("Sum of two matrices: "); A.plus(B).show
gauss elimination of system of linear equations using java code
gauss elimination of system of linear equations using java code  Here...); System.out.println("enter no of equations "); N = s.nextInt...]; } System.out.println("enter the co-efficient of equations
Pick at Random
the entry from the array before selecting another name at random
Random numbers - Development process
Random numbers  hi, How to generate unique random numbers between range like(10 to 50)  Hi friend, class RandomNumber { public static void main(String[] args) { //set the variable aNumber
Random Creation of password
to generate a random password and insert into database... Please help me out...Random Creation of password  Dear Sir I have created a form with some details in it.When clicking on the submit button it gives me a password
constructor program
constructor program  write a program to calculate the gross salary and net salary of an employee based on the following attributes: empno,empname,emp address,basic,hra,da,ta,vehicle loan,personel loan use the scanner class
random numbers
random numbers  Hi I need some help with the code for the this program. This program should randomly choose a number between 1 and 1000, and then challenge the user to guess what it is, giving hints ('too high!' or 'too low
Default Package
Default Package  Can we import default packages???   Yes, you can import the default packages. But there will be no error or exception, if you will not import default packages. Otherwise, importing packages is must
constructor in java
constructor in java  Ex: public class A { public A(){ System.out.println("A"); } public A(int i){ this(); System.out.println(i); } } public class B extends A{ public B (){ System.out.println("B"); } public B (int i
Advertisements
 

 

 

DMCA.com