Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives:

a. randomize() - Returns a random int between min and max inclusive. Must have two int parameters.

b. randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter.

c. randomize() - Returns a random double between min and max inclusive. Must have two double parameters.

d. randomize() - Returns a random double between 0 and max inclusive. Must have one double parameter.

Respuesta :

Answer:

The Java code given below

Explanation:

//import package

import java.util.Scanner;

//Java class

class Lesson_35_Activity {

  // returns random int b/t min and max inclusive; has 2 int parameters

  public static int randomize(int min, int max) {

      int x = (int) (Math.random() * ((max - min) + 1)) + min;

      return x;

  }

  // returns random int b/t 0 and max inclusive; has one int parameter

  public static int randomize(int max) {

      int x = (int) (Math.random() * (max + 1));

      return x;

  }

  // returns random double b/t min and max inclusive; two double parameters

  public static double randomize(double min, double max) {

      double x = (double) (Math.random() * ((max - min) + 1)) + min;

      return x;

  }

  // returns random double b/t 0 and max inclusive; has one double parameter.

  public static double randomize(double max) {

      double x = (double) (Math.random() * (max + 1));

      return x;

  }

  // main method, which is entry point of the program

  public static void main(String[] args) {

      // object of Scanner class

      Scanner scan = new Scanner(System.in);

      // asking min and max number

      System.out.print("Enter min number : ");

      int mi = scan.nextInt();// reading min number

      System.out.print("Enter max number : ");

      int ma = scan.nextInt();// reading max number

      // checking number

      if (mi < ma) {

          System.out.println(randomize(mi, ma));// method call

          System.out.println(randomize(0, ma));// method call

          double mii = mi;

          double maa = ma;

          System.out.printf("%.2f", randomize(mii, maa));

          System.out.printf("\n%.2f", randomize(0, maa));

      } else {

          // when minimum number is greater than maximum number then display

          System.out.println("Enter min number " + mi + " should be less than max " + ma);

      }

  }

}

Answer:

The Java code given below

Explanation:

//import package

import java.util.Scanner;

//Java class

class Lesson_35_Activity {

  // returns random int b/t min and max inclusive; has 2 int parameters

  public static int randomize(int min, int max) {

      int x = (int) (Math.random() * ((max - min) + 1)) + min;

      return x;