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

Using the Math class API’s, Write a program named NumberGame. The main method sh

ID: 3629543 • Letter: U

Question

Using the Math class API’s, Write a program named NumberGame. The main method should look like this:


public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("What is the minimum number?");
int min = scan.nextInt();
System.out.println("What is the maximum number?");
int max = scan.nextInt();
int first = generate(min,max);
int second = generate(min,max);
int third = generate(min,max);

// call the methods
print(first,second,third);
calcMin(first,second,third);
calcMax(first,second,third);
sum(first,second,third);
sumCube(first,second,third);
sort(first,second,third);
} //end main

// write a method that will generate a random number
// the parameters are the min and max value for it
public static int generate(int min, int max) {
int number = min + (int) (Math.random() * (max-min+1));
return number;
}


Sample output:

The numbers are: 42 37 98
The minimum is: 37
The maximum is: 98
The sum of the numbers is: 177
The cube of the sum of the numbers is: 5545233
The sorted numbers are: 37 42 98

Explanation / Answer

please rate - thanks

in the methods parameter f=first, s=second, t=third;

import java.util.*;
public class untitled
{public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("What is the minimum number?");
int min = scan.nextInt();
System.out.println("What is the maximum number?");
int max = scan.nextInt();
int first = generate(min,max);
int second = generate(min,max);
int third = generate(min,max);

// call the methods
print(first,second,third);
calcMin(first,second,third);
calcMax(first,second,third);
sum(first,second,third);
sumCube(first,second,third);
sort(first,second,third);
} //end main

// write a method that will generate a random number
// the parameters are the min and max value for it
public static int generate(int min, int max) {
int number = min + (int) (Math.random() * (max-min+1));
return number;
}
public static void print(int f, int s, int t)
{System.out.println("The numbers are: "+f+" "+s+" "+t);
}
public static void calcMin(int f, int s, int t)
{int min=f;
if(s<min)
    min=s;
if(t<min)
    min=t;
System.out.println("The minimum is: "+min);
}
public static void calcMax(int f, int s, int t)
{int max=f;
if(s>max)
    max=s;
if(t>max)
    max=t;
System.out.println("The maximum is: "+max);
}
public static void sum(int f, int s, int t)
{int sum=f+s+t;
System.out.println("The sum of the numbers is: "+sum);
}
public static void sumCube(int f, int s, int t)
{int sum=f+s+t;
sum=sum*sum*sum;
System.out.println("The cube of the sum of the numbers is: "+sum);
}
public static void sort(int f, int s, int t)
{int s1,s2,s3;
if(f<s)
   {if(f<t)
        {s1=f;        //num1 is smallest
        if(s<t)
              {s2=s;
                s3=t;
                }
         else
                {s2=t;
                s3=s;
                }
            }
       else              //t is smallest
           {s1=t;
            s2=f;
            s3=s;
            }
        }
    else               //s or t smallest
        if(s<t)
             {s1=s;   //s smallest
               if(f<t)
                    {s2=f;
                    s3=t;
                    }
                else
                    {s2=t;
                    s3=f;
                    }
                }
            else
                {s1=t;
                s2=s;
                s3=f;
                }
System.out.println("The sorted numbers are: "+s1+" "+s2+" "+s3);

}
}

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