Question

In: Computer Science

in JAVA Create a class called “MinMax” that satisfies the following requirements: a. create an integer...

in JAVA

Create a class called “MinMax” that satisfies the following requirements:
a. create an integer array called nums that has 20 cells
b. generate a random number between 5 and 30, and populate the array nums
c. print the minimum and maximum number in the array nums
d. print sum and average of numbers in the array nums

Your output look like this: (Note: numbers shown below will be different in your program due to the random numbers)
minimum number = 6
maximum number = 29
sum = 123
average = 67.23

Solutions

Expert Solution

ANSWER: HEre i am giving you the code and output please like it.

CODE:

import java.util.concurrent.ThreadLocalRandom;
public class MinMax {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int arr [] = new int[20];
      
      
   for (int i = 0; i < 20; i++) {
       arr[i] = ThreadLocalRandom.current().nextInt(5, 30);
   }
   int max=arr[0];
   int min=arr[0];
   int sum=0;
   for(int i=0;i<20;i++) {
       if(arr[i]>max)
           max=arr[i];
       if(arr[i]<min)
           min=arr[i];
      
       sum+=arr[i];
   }
  
   System.out.println("minimum number = "+min);
   System.out.println("maximum number = "+max);
   System.out.println("sum = "+sum);
   double avg=(double)sum/20;
   System.out.printf("average = %.2f",avg);
      
   }

}

OUTPUT:


Related Solutions

Using Java: Create a class called MyNumber with an integer private attribute. Create a constructor that...
Using Java: Create a class called MyNumber with an integer private attribute. Create a constructor that defines an integer parameter to set the private integer attribute. Create a setter that validates the attribute does not accept a value lower than 2 or the method will throw a IllegalArgumetException. Create a getter to return the private integer attribute value. Define a public method that is called isPrime() that returns a boolean and implements the Sieve of Eratosthenes method. Define a public...
(32%) Create a class of function objects called StartsWith that satisfies the following specification: when initialized...
(32%) Create a class of function objects called StartsWith that satisfies the following specification: when initialized with character c, an object of this class behaves as a unary predicate that determines if its string argument starts with c. For example, StartsWith(’a’) is a function object that can be used as a unary predicate to determine if a string starts with an a. So StartsWith(’a’)("alice") would return true but StartsWith(’a’)("bob") would return false. The function objects should return false when called...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
Write a program that meets the following requirements: Cat Class Create a class called Cat which...
Write a program that meets the following requirements: Cat Class Create a class called Cat which has only the following instance variables: - name - breed - number of legs - year born Create the no-argument constructor Create the constructor which uses all fields as parameters Write the getter and setter methods for all instance variables Override the toString method using the example shown above There should be NO main method in the Cat class. CatTester Class Create a class...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Write a Java class called GuessMyNumber that prompts the user for an integer n, tells the...
Write a Java class called GuessMyNumber that prompts the user for an integer n, tells the user to think of a number between 0 and n−1, then makes guesses as to what the number is. After each guess, the program must ask the user if the number is lower, higher, or correct. You must implement the divide-and-conquer algorithm from class. In particular, you should round up when the middle of your range is in between two integers. (For example, if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT