Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*GradeBook.java // Fig. 7.18: GradeBook.java // GradeBook class using a two-dimensional array to store grades. public class GradeBook2 { private String courseName; // name of

image text in transcribedimage text in transcribed

*GradeBook.java

// Fig. 7.18: GradeBook.java // GradeBook class using a two-dimensional array to store grades.

public class GradeBook2 { private String courseName; // name of course this grade book represents private int[][] grades; // two-dimensional array of student grades

// two-argument constructor initializes courseName and grades array public GradeBook2(String courseName, int[][] grades) { this.courseName = courseName; this.grades = grades; } // method to set the course name public void setCourseName(String courseName) { this.courseName = courseName; } // method to retrieve the course name public String getCourseName() { return courseName; } // perform various operations on the data public void processGrades() { // output grades array outputGrades(); // call methods getMinimum and getMaximum System.out.printf("%n%s %d%n%s %d%n%n", "Lowest grade in the grade book is", getMinimum(), "Highest grade in the grade book is", getMaximum()); // output grade distribution chart of all grades on all tests outputBarChart(); }

// find minimum grade public int getMinimum() { // assume first element of grades array is smallest int lowGrade = grades[0][0]; // loop through rows of grades array for (int[] studentGrades : grades) { // loop through columns of current row for (int grade : studentGrades) { // if grade less than lowGrade, assign it to lowGrade if (grade

for (int[] studentGrades : grades) { // loop through columns of current roW for (int grade : studentGrades) { // if grade greater than highGrade, assign it to highGrade if (grade > highGrade) { highGrade = grade; } } } return highGrade; } // determine average grade for particular set of grades public double getAverage(int[] setOfGrades) { int total = 0; // sum grades for one student for (int grade : setOfGrades) { total += grade; } // return average of grades

return (double) total / setOfGrades.length; }

// output bar chart displaying overall grade distribution public void outputBarChart() { System.out.println("Overall grade distribution:"); // stores frequency of grades in each range of 10 grades int[] frequency = new int[11];

// for each grade in GradeBook, increment the appropriate frequency for (int[] studentGrades : grades) { for (int grade : studentGrades) { ++frequency[grade / 10]; } }

// for each grade frequency, print bar in chart for (int count = 0; count

// print bar of asterisks for (int stars = 0; stars

// create a column heading for each of the tests for (int test = 0; test

System.out.println("Average"); // student average column heading // create rows/columns of text representing array grades for (int student = 0; student

for (int test : grades[student]) { // output student's grades System.out.printf("%8d", test); } // call method getAverage to calculate student's average grade; // pass row of grades as the argument to getAverage double average = getAverage(grades[student]); System.out.printf("%9.2f%n", average); } } }

GradeBookTest2.java

// Fig. 7.19: GradeBookTest.java // GradeBookTest creates GradeBook object using a two-dimensional array // of grades, then invokes method processGrades to analyze them. public class GradeBookTest2 { // main method begins program execution public static void main(String[] args) {

// two-dimensional array of student grades int[][] gradesArray = {{87, 96, 70}, {68, 87, 90}, {94, 100, 90}, {100, 81, 82}, {83, 65, 85}, {78, 87, 65}, {85, 75, 83}, {91, 94, 100}, {76, 72, 84}, {87, 93, 73}};

GradeBook2 myGradeBook = new GradeBook2( "CS101 Introduction to Java Programming", gradesArray); System.out.printf("Welcome to the grade book for%n%s%n%n", myGradeBook.getCourseName()); myGradeBook.processGrades(); } }

(1) In GradeBook2 class, modify the constructor so that it has three parameters: the course name, the number of students, and the number of exams. Define number of students and the number of exams as int type of variables. And then in the constructor to build an appropriately sized two-dimensional array by using those parameters. And then, set each element of the new two-dimensional array to-1 to indicate that no grade has been entered for that element in the contructor. (2) In GradeBook2 class, add a setGrade method that sets one grade for a particular student on a particular . . (3) In GradeBook2 class, modify outputGrades method so that average grade for each test will also be printed out. For example, The grades are Test 1 Test 2 Test) Average Student 1 87 96 84.33 Student 2 68 87 90 81.67 Student 94 100 94.67 Student 4 100 81 82 87.67 Student 5 03 65 05 77.67 Student /6.67 Student 7 85 75 83 81.00 Student 8 91 94 109 95.00 Student 76 72 14 77.33 Student 10 87 9) 7) B4.33 werage 34.9 35.0 12.2 Lowest grade in the grade book is 65 Highest grade in the grade book is 100 (Figure 3.2) (4) Draw a UML class diagram to show the modified structure of GradeBook2 class (including all instance variables and methods) (in GradeBook2revised.java). Save your UML class diagram in a Word document or a PDF document named "GradeBook2_UMLclassDiagram". (5) In GradeTest2 class (in GradeTest2revised.java), modify the main method to ask users to input the number of students and number of exams for the GradeBook2 object, and then to develop a loop to ask the user to enter one grade at a time by using setGrade method to add test grades for 10 students. After received all student grades from user inputs, the main method will print out the course name, and display the grade statistics by calling getCourseName method, and processGrades method. (6) Compile and test your program to make sure there is no syntax, logical, or run-time error

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_2

Step: 3

blur-text-image_3

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

What announcement did the SEC make on August 27, 2008?

Answered: 1 week ago

Question

5. To determine the financial benefits and costs of the program.

Answered: 1 week ago