Java This program will do several things. Implement the features as individual m
ID: 3691622 • Letter: J
Question
Java
This program will do several things. Implement the features as individual methods. Use the main() method to create and populate the array with 30 random integers in the range of 0 to 500. Pass the array to a method named fvLowVal and in the method, find and display the lowest value. Pass the array to a method named fvHighVal and in the method, find and display the highest value. Pass the array to a method named fdCalcMean and in the method, calculate the mean; return the mean to the main() method and display it there to two places to the right of the decimal point. Output example (code accordingly to get this verbiage and format; your actual values will vary):
Lowest value: 3
Highest value: 197
Mean value: 47.23
Explanation / Answer
import java.util.*;
public class RandomArray
{
public static void main(String args[])
{
int smallest = randomThirty[0];
int largetst = randomThirty[0];
//main method which creates an array to store 30 integers between 0 to 500
int[] randomThirty = new int[30];
for (int i = 0; i < randomThirty.length; i++)
{
randomThirty[i] = (int)(Math.random() * 501);
}
fvLowVal( randomThirty);
fvHighVal (randomThirty);
fdCalcMean (randomThirty)
}//main
public static fvLowVal(int[] randomThirty)
{
//find smallest element in randomthirty array
for(int i=1; i< randomThirty .length; i++)
{
if (randomThirty[i] < smallest)
smallest = randomThirty[i];
}
System.out.println("Lowest value : " + smallest);
}//fvLowval
public static fvHighVal (int[] randomThirty)
{
//find largest element in randomthirty array
for(int i=1; i< randomThirty .length; i++)
{
if (randomThirty[i] > largetst)
largetst= randomThirty[i];
}
System.out.println("Highest value : " + largetst);
}//fvHighval
public static fdCalcMean (int[] randomThirty)
{
//find mean element in randomthirty array
float total=0,mean;
for(int i=1; i< randomThirty .length; i++)
{
total=total+ randomThirty[i];
}
mean=total/randomThirty .length;
System.out.println("Mean value : " + mean);
}//fdcalcmean
}//class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.