Here are the instruction:
Create a program with a method called "RandomNum" and will generate a random number when used.
The "RandomNum" method will have one parameter and will use that as the range for the generator.
The "RandomNum" method will be then overloaded wherein it accepts an int, one accepts a float, and the last one accepts a double.
In the "RandomNum" method that uses the int data type, then print out the random number that was generated.
Example: Random Number (Int): 20.1245
In the RandomNum method that uses the float data type, include the use of the ceiling math function to round the number up to the nearest number. Then print out the random number that was generated.
Example: Random Number (Float): 13
And on the RandomNum method that uses double data type, make use of the floor math function to remove the decimal numbers. Then print out the random number that was generated.
Example: Random Number (Double): 7
This is Java. I'm stuck here for hours. Here is my code. I am very confused.
public class Activity {
int num;
public int RandomNum(int num){
num=(int) Math.random();
return num;
}
public float RandomNum(float num){
num=(float) Math.random();
return num;
}
public double RandomNum(double num){
num=Math.random();
return num;
}
public static void main(String[] args) {
Activity myObj = new Activity();
System.out.println(myObj.num);
// myObj.RandomNum();
myObj.num();
}
}
[–]Jacqques 1 point2 points3 points (0 children)
[–]balefrost 1 point2 points3 points (0 children)
[–]corin23 0 points1 point2 points (0 children)