In: Computer Science
1. Design and implement a class called RandomArray,
which has an integer array. The constructor receives the size of
the array to be allocated, then populates the array with random
numbers from the range 0 through the size of the array. Methods are
required that
return the minimum value, maximum value, average value, and a
String representation of the array values. Document your design
with a UML Class diagram. Create a separate driver class that
instantiates a RandomArray object and outputs its contents and the
minimum, maximum, and average values.
code
RandomArray.java class
public class RandomArray
{
private int []arr;
public RandomArray(int size)
{
arr=new int[size];
int max = size;
int min = 0;
int range = max - min + 1;
for(int i=0;i<size;i++)
arr[i]=(int)(Math.random() * range) + min;
}
public int minimum()
{
int min=arr[0];
for(int i=1;i<arr.length;i++)
if(min>arr[i])
min=arr[i];
return min;
}
public int maximum()
{
int max=arr[0];
for(int i=1;i<arr.length;i++)
if(max<arr[i])
max=arr[i];
return max;
}
public double average()
{
double sum=0;
for(int i=0;i<arr.length;i++)
sum+=arr[i];
return sum/arr.length;
}
@Override
public String toString() {
String str="";
for(int i=0;i<arr.length-1;i++)
str+=arr[i]+",";
str+=arr[arr.length-1];
return "Array is ["+str+"]";
}
}
Driver class
TestRandomArray.java file
public class TestRandomArray {
public static void main(String[] args) {
RandomArray arr1=new RandomArray(7);
System.out.println(arr1);
System.out.println("Minimum element is : "+arr1.minimum());
System.out.println("Minimum element is : "+arr1.maximum());
System.out.println("Average of the array is :
"+arr1.average());
}
}
output

If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.