Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program, use following method. Need Comment Output: How many students do you have in the class: 4 Enter grade of Student 1:

Write a java program, use following method. Need Comment

Output:

How many students do you have in the class: 4

Enter grade of Student 1: 10

Enter grade of Student 2: 100

Enter grade of Student 3: 20

Enter grade of Student 4: 30

The grades are: 10.0, 100.0, 20.0, 30.0

The sorted grades are: 10.0, 20.0, 30.0, 100.0

Mean = 40.0

Median = 25.0

Min = 10.0 Max = 100.0

public static double[] populateGrades() construct the array of type double, create Scanner class object to read in the number of students and their grades from the keyboard, store the grades in the array and then return that array.

. public static void sortGrades(double grades[]) it takes the grades array as an argument and sorts the values in ascending order (from low to high). You can use Arrays.sort() method to sort the array.

public static double getMean(double grades[]) it takes the grades array as an argument, calculates the mean of all values and returns the result.

public static double getMedian(double grades[]) it takes the grades array as an argument, calculates the median of all values and returns the result

public static double[] getMinMax(double grades[]) it takes the grades array as an argument, calculates the minimum and maximum of all values and returns the result in array. The result array has the minimum and maximum values in index 0 and 1, respectively

public static void printGrades(double grades[]) it takes the grades array as an argument, prints the content of the array from the left (index 0) to right. The grades are printed in the following format (separated by comma and a space). Format: 87.0, 89.0, 95.0, 97.0

public static void main(String args[]) You need to call the methods you defined above to complete this method. Here is the order you must follow: 1. Call populateGrades() method and store the returned array reference using a local array reference. 2. Print the grades using the printGrades() method. You need to pass the array you populated using populateGrades() method. 3. Sort the grades using sortGrades() method. You can use the sorted array for rest of the tasks. 4. Print the sorted grades using printGrades() method. 5. Compute mean using the getMean() method and print it. 6. Compute median using the getMedian() method and print it. 7. Find minimum and maximum using getMinMax() method and print.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions