In: Computer Science
JAVA Programming
Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once The program should output the average, largest, and smallest of 5 numbers.
You must implement the methods listed below in your program.
static float getAverage(int[] data) {...}
static int getLargest(int[] data) {...}
static int getSmallest(int[] data) {...}
import java.util.Scanner; public class DataProcess { static float getAverage(int[] data) { float total = 0; for (int i = 0; i < data.length; i++) { total += data[i]; } return total / data.length; } static int getLargest(int[] data) { int max = data[0]; for (int i = 0; i < data.length; i++) { if (data[i] > max) max = data[i]; } return max; } static int getSmallest(int[] data) { int min = data[0]; for (int i = 0; i < data.length; i++) { if (data[i] < min) min = data[i]; } return min; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter 5 numbers: "); int[] data = new int[5]; for (int i = 0; i < data.length; i++) { data[i] = in.nextInt(); } System.out.println("Average: " + getAverage(data)); System.out.println("Largest: " + getLargest(data)); System.out.println("Smallest: " + getSmallest(data)); } }