Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming: Please help me add and improve functionality of this java clas

ID: 3574948 • Letter: J

Question

Java Programming:

Please help me add and improve functionality of this java class which generates X random Integer values between 0 and Y. Program is posted below

/* Name: RandomIntGenerator.java
* Purpose: Create a number generator
* using command line input for how many to generate
* and the range in which to generate.
*/
public class RandomIntGenerator{
    
    public static void main(String[] args){
        
        if (args.length == 2){
            
            //Parse the command line input arguments to integers
            int xGeneratorCount = Integer.parseInt(args[0]);
            int yGeneratorRange = Integer.parseInt(args[1]);
            
            
            //Loop through xGeneratorCount
            for (int i = 0; i < xGeneratorCount; i++){
                //Generate random numbers from 0 to yGeneratorRange inclusive
                int myGeneratedNumbers = (int) (Math.random() * (yGeneratorRange + 1) );
                
                //Print out random numbers that are generated
                System.out.println("Random Number "+(i+1)+": "+myGeneratedNumbers);
            }
                        
        }else{
            //Output error message if arguement length is not equal to 2
            System.out.println("Invalid input. Use following format: "+
            " java RandomIntGenerator <int x> <int y>"+
            " Where x is the integer specifying Generator Count and y is the integer specifying Generator range.");
        }
        
    }

}

Explanation / Answer

import java.util.Scanner;

/* Name: RandomIntGenerator.java
* Purpose: Create a number generator
* using command line input for how many to generate
* and the range in which to generate.
*/
public class RandomIntGenerator {

   public static void main(String[] args) {
       /*if (args.length == 2){
           //Parse the command line input arguments to integers
           int xGeneratorCount = Integer.parseInt(args[0]);
           int yGeneratorRange = Integer.parseInt(args[1]);*/

      
       // For directly taking input from the user.
       Scanner in = new Scanner(System.in);
       System.out.println("Enter the Number of times the Random Number should Print: ");
       int xGeneratorCount = in.nextInt();
//       System.out.println("Enter the min range: ");
//       int y1GeneratorRange = in.nextInt();
       System.out.println("Enter the max range: ");
       int yGeneratorRange = in.nextInt();

       // Loop through xGeneratorCount
       for (int i = 0; i < xGeneratorCount; i++) {
           // Generate random numbers from 0 to yGeneratorRange inclusive
           int myGeneratedNumbers = (int) (Math.random() * (yGeneratorRange+1));

           // Print out random numbers that are generated
           System.out.println("Random Number " + (i + 1) + ": " + myGeneratedNumbers);
       }
   }
}
       /*}else{
       // Output error message if argument length is not equal to 2
       System.out.println("Invalid input. Use following format: " + " java
       RandomIntGenerator <int x> <int y>"
       + " Where x is the integer specifying Generator Count and y is the
       integer specifying Generator range.");
       }*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote