Exercise GradesStatistics (Method): Write a program called GradesStatistics, which reads in n grades (of int between 0 and 100, inclusive) and displays the average, minimum, maximum, median and standard deviation. Display the floating-point values upto 2 decimal places. Your output shall look like: Enter the number of students: 4 Enter the grade for student 1: 50 Enter the grade for student 2: 51 Enter the grade for student 3: 56 Enter the grade for student 4: 53 {50,51,56,53} The average is: 52.50 The median is: 52.00 The minimum is: 50 The maximum is: 56 The standard deviation is: 2.29 The formula for calculating standard deviation is: Hints: public class GradesStatistics { public static int[] grades; // Declare an int[], to be allocated later. // This array is accessible by all the methods. public static void main(String[] args) { readGrades(); // Read and save the inputs in int[] grades printArray(grades); System.out.println("The average is " + average(grades)); System.out.println("The median is " + median(grades)); System.out.println("The minimum is " + min(grades)); System.out.println("The maximum is " + max(grades)); System.out.println("The standard deviation is " + stdDev(grades)); } // Prompt user for the number of students and allocate the global "grades" array. // Then, prompt user for grade, check for valid grade, and store in "grades". public static void readGrades() { ....... } // Print the given int array in the form of {x1, x2, x3,..., xn}. public static void printArray(int[] array) { ....... } // Return the average value of the given int[] public static double average(int[] array) { ...... } // Return the median value of the given int[] // Median is the center element for odd-number array, // or average of the two center elements for even-number array. // Use Arrays.sort(anArray) to sort anArray in place. public static double median(int[] array) { ...... } // Return the maximum value of the given int[] public static int max(int[] array) { int max = array[0]; // Assume that max is the first element // From second element, if the element is more than max, set the max to this element. ...... } // Return the minimum value of the given int[] public static int min(int[] array) { ....... } // Return the standard deviation of the given int[] public static double stdDev(int[] array) { ....... } } Take note that besides readGrade() that relies on global variable grades, all the methods are self-contained general utilities that operate on any given array.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Exercise GradesStatistics (Method): Write a program called GradesStatistics, which reads in n grades (of int between 0 and 100, inclusive) and displays the average, minimum, maximum, median and standard deviation. Display the floating-point values upto 2 decimal places. Your output shall look like:
    Enter the number of students: 4
    Enter the grade for student 1: 50
    Enter the grade for student 2: 51
    Enter the grade for student 3: 56
    Enter the grade for student 4: 53
    {50,51,56,53}
    The average is: 52.50
    The median is: 52.00
    The minimum is: 50
    The maximum is: 56
    The standard deviation is: 2.29
    The formula for calculating standard deviation is:

    Hints:
    public class GradesStatistics {
    public static int[] grades; // Declare an int[], to be allocated later.
    // This array is accessible by all the methods.

    public static void main(String[] args) {
    readGrades(); // Read and save the inputs in int[] grades
    printArray(grades);
    System.out.println("The average is " + average(grades));
    System.out.println("The median is " + median(grades));
    System.out.println("The minimum is " + min(grades));
    System.out.println("The maximum is " + max(grades));
    System.out.println("The standard deviation is " + stdDev(grades));
    }

    // Prompt user for the number of students and allocate the global "grades" array.
    // Then, prompt user for grade, check for valid grade, and store in "grades".
    public static void readGrades() { ....... }

    // Print the given int array in the form of {x1, x2, x3,..., xn}.
    public static void printArray(int[] array) { ....... }

// Return the average value of the given int[]
public static double average(int[] array) { ...... }

// Return the median value of the given int[]
// Median is the center element for odd-number array,
// or average of the two center elements for even-number array.
// Use Arrays.sort(anArray) to sort anArray in place.
public static double median(int[] array) { ...... }

// Return the maximum value of the given int[]
public static int max(int[] array) {
int max = array[0]; // Assume that max is the first element
// From second element, if the element is more than max, set the max to this element.
......
}

// Return the minimum value of the given int[]
public static int min(int[] array) { ....... }

// Return the standard deviation of the given int[]
public static double stdDev(int[] array) { ....... }
}
Take note that besides readGrade() that relies on global variable grades, all the methods are self-contained general utilities that operate on any given array.

  1. Exercise GradesHistogram (Method): Write a program called GradesHistogram, which reads in n grades (as in the previous exercise), and displays the horizontal and vertical histograms. For example:

  0 -  9: ***

 10 - 19: ***

 20 - 29:

 30 - 39:

 40 - 49: *

 50 - 59: *****

 60 - 69:

 70 - 79:

 80 - 89: *

 90 -100: **

 

                                *                          

                                *                          

  *     *                       *                          

  *     *                       *                       *   

  *     *                 *     *                 *     *  

 0-9  10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-100

Hints:

  • Declare a 10-element int arrays called bins, to maintain the counts for [0,9], [10,19], ..., [90,100]. Take note that the bins's index is mark/10, except mark of 100.
  • Write the codes to print the star first. Test it. Then print the labels.
  • To print the horizontal histogram, use a nested loop:
  • for (int binNum = 0; binNum < bins.length; binNum++) { // each row for one bin
  • // Print label for each row
  • .......
  • for (int starNum = 0; starNum < bins[binNum]; starNum++) {  // each column is one star
  • .......
  • }
  • ......  // print newline

}

  • To print the vertical histogram, you need to find the maximum bin count (called maxBinCount) and use a nested loop:
  • for (int level = maxBinCount; level >= 1; level--) { // each row for one count level
  • for (int binNum = 0; binNum < bins.length; binNum++) {  // each column for one bin
  • // if (bin's count >= level) print *
  •   // else print blank.
  • }
  • ......  // print newline

}

  1. Exercise (Array and Method): Write a program called PrintChart that prompts the user to input n non-negative integers and draws the corresponding horizontal bar chart. Your program shall use an int array of length n; and comprise methods readInput() and printChart(). A sample session is as follows:

Enter number of bars: 4

Enter bar 1 value: 4

Enter bar 2 value: 3

Enter bar 3 value: 5

Enter bar 4 value: 7

 

**** (4)

*** (3)

***** (5)

******* (7)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education