Default constructor generate two random equations

Ads

 
 

Share on Google+Share on Google+

Asim Aleem
Default constructor generate two random equations
0 Answer(s)      4 years and a month 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());



    }
          }
Ads
View Answers
Ads









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
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
Java constructor
Java constructor  When does the compiler supply a default constructor for a class
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
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 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
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
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads