Question

In: Computer Science

Write a complete Java code that contain two classes. A GradeBook and a GradeBookTester. - The...

Write a complete Java code that contain two classes. A GradeBook and a GradeBookTester.

- The GradeBook class contains the followings:

- An array of grades (integer array) declared as a field.

- A constructor that takes an integer value as parameter (len), and creates the grades array of size equals to len.

- A method called fillArray that fills the grades array with random integers. Acceptable values are between 1 and 100 (inclusive)

- A method called printStatistics that prints 4 values: the average of the grades, the minimum grade, the maximum grade, and the median grade (the middle value of the sorted array).

- The GradeBookTester contains the main and do the followings:

- Uses the input dialog to ask the user to enter an integer value (assume that the user will enter a value that is non-zero and positive / no need to check)

- creates an object of GradeBook class while passing the entered value as parameter.

- calls the functions fillArray and printStatistics for testing.

Please Solve As soon as

Solve quickly I get you thumbs up directly

Thank's

Solutions

Expert Solution

GradeBook.java

import java.util.Random;

public class GradeBook {

    private int grades[];

    public GradeBook(int size) {

        grades = new int[size];

    }

    // method to fill the array

    public void fillArray() {

        Random rn=new Random();

        // loop through the array and randomly fill it

        for (int i = 0; i < grades.length; i++) {

            grades[i] = rn.nextInt(100) + 1;

        }

    }

    // print the statistics of the array values

    public void printStatistics() {

        int max = grades[0], min = grades[0];

        float avg=0, median=0;

        // loop through the array

        for (int a : grades) {

            if (a < min)

                min = a;

            if (a > max)

                max = a;

            avg += a;

        }

        avg = avg / grades.length;

        // sort the array

        for (int i = 0; i < grades.length - 1; i++) {

            for (int j = 0; j < grades.length - i - 1; j++) {

                if (grades[j] > grades[j + 1]) {

                    int t = grades[j];

                    grades[j] = grades[j + 1];

                    grades[j + 1] = t;

                }

            }

        }

        int l = grades.length;

        median = l % 2 == 0 ? (grades[l / 2] + grades[l / 2 + 1]) / 2 : grades[l / 2];

        System.out.println("Minimum : " + min + "\nMaximum : " + max + "\nAverage : " + avg + "\n Median : " + median);

    }

}

Screenshot

GradeBookTester.java

import java.util.*;

public class GradeBookTester {

    public static void main(String args[]) {

        Scanner x = new Scanner(System.in);

        // get user input

        System.out.print("Enter size of grades array : ");

        int l = Integer.parseInt(x.nextLine());

        // call GradeBook methods

        GradeBook grade = new GradeBook(l);

        grade.fillArray();

        grade.printStatistics();

    }

}

SCreenshot

Output


Related Solutions

Write code in java using the LinkedList connecting two different classes. For example, Employee and EmployeeList...
Write code in java using the LinkedList connecting two different classes. For example, Employee and EmployeeList are two different classes that are used to create the assignment.
write a program in java that contain a class for botique . data member include code...
write a program in java that contain a class for botique . data member include code , color , size , quantity . your class should contains all accessor and mutator methods , non paraqmetric constructor , parametric constructor , input andvidsplay method
Java program Create two classes based on the java code below. One class for the main...
Java program Create two classes based on the java code below. One class for the main method (named InvestmentTest) and the other is an Investment class. The InvestmentTest class has a main method and the Investment class consists of the necessary methods and fields for each investment as described below. 1.The Investment class has the following members: a. At least six private fields (instance variables) to store an Investment name, number of shares, buying price, selling price, and buying commission...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
Objective: Using Java coding language, complete each "TO-DO" section for the following classes. Shape code (for...
Objective: Using Java coding language, complete each "TO-DO" section for the following classes. Shape code (for reference, nothing to complete here): import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.io.RandomAccessFile; public abstract class Shape extends Rectangle {    public int id;    public Color color;    public int xSpeed, ySpeed;       public Shape(int id, int x, int y, int width, int height, Color color, int xSpeed, int ySpeed) {        super(x,y,width,height);        this.id = id;        this.color...
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel....
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel. A dog consists of the following information: • An integer age. • A string name. If the given name contains non-alphabetic characters, initialize to Wolfy. • A string bark representing the vocalization the dog makes when they ‘speak’. • A boolean representing hair length; true indicates short hair. • A float weight representing the dog’s weight (in pounds). • An enumeration representing the type...
Write a program to multiply two polynomials. Code needed in Java.
Write a program to multiply two polynomials. Code needed in Java.
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java program to reverse a stack of characters. Make your own assumption and your own design on the methods signature, inputs, outputs, and the full main program.
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread prints all capital letters 'A' to'Z'. The other thread prints all odd numbers from 1 to 21.
in java language. There are three classes for the project, and two inner classes defined in...
in java language. There are three classes for the project, and two inner classes defined in the Cuboid class. Create the following classes: •   Shape. It’s an abstract class with two abstract methods, area and perimeter. •   Rectangle. It’s a concrete class that extends Shape. Implement area() and perimeter(). Implement the compareTo(object) method to sort rectangles by area in ascending order. •   Cuboid. It’s a concrete class that extends Rectangle. A cuboid is a 3D rectangle. The shape has a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT