Ask Question
7 May, 02:49

Write a Java Program that can compute the mean, median, the highest, and the lowest of the students' scores in a class. First, the user inputs the number of students in the class and you capture this number. Then the user inputs the grades of all the students in the class. After capturing all the inputs, your program should output the mean, the median, the highest, and the lowest. Hint: You need to use Array to capture the grade inputs from users.

+3
Answers (1)
  1. 7 May, 04:34
    0
    The program of this question can be given as:

    Program:

    import java. util.*; / /import package.

    class Main / /define class.

    {

    public static double mean (int x[], int n) / /define function mean

    {

    //function body.

    int total = 0;

    for (int k = 0; k < n; k++)

    total = total + x[k];

    return (double) total / (double) n; / /return value.

    }

    public static int mini (int[] a, int n) / /define function mini

    {

    //function body.

    int result = a[0];

    for (int k=0; k
    if (result > a[k])

    //result value

    result = a[k];

    return result;

    }

    public static int maxi (int[] a, int n) / /define function maxi

    {

    //function body.

    int result = a[0];

    for (int k=0; k
    if (result < a[k])

    //result function

    result = a[k];

    return result;

    }

    public static double median (int x[], int n) / /define function median

    {

    //function body.

    Arrays. sort (x);

    if (n % 2! = 0)

    //return value

    return (double) x[n / 2];

    return (double) (x[ (n - 1) / 2] + x[n / 2]) / 2.0;

    }

    //define main function.

    public static void main (String ar [])

    {

    Scanner object = new Scanner (System. in); / /creating Scanner class object.

    System. out. print ("Enter total students: "); / /print message.

    int n = object. nextInt ();

    int[] grades = new int[n];

    System. out. print ("Enter number of students: ");

    for (int j=0; j
    grades[j] = object. nextInt ();

    //calling function and print values.

    System. out. println ("Mean = " + mean (grades, n));

    System. out. println ("Median = " + median (grades, n));

    System. out. println ("Highest = " + maxi (grades, n));

    System. out. println ("Lowest = " + mini (grades, n));

    }

    }

    output:

    Enter total students: 4

    Enter the number of students: 70

    80

    69

    89

    Mean = 77.0

    Median = 75.0

    Highest = 89

    Lowest = 69

    Explanation:

    In the above program firstly we import package that is used for input from the user. Then we define a method that is mean, median, highest and lowest. The working of the method is the same as the name. All functions return to value main function. At last, we define the main function. In this function, we create the scanner class object for user input. Then we pass the value to function and print it.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a Java Program that can compute the mean, median, the highest, and the lowest of the students' scores in a class. First, the user ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers