Modify the GradeBook class of Fig.7.16 so that the constructor accepts as parameters the number of students
Question:
Modify the GradeBook class of Fig.7.16 so that the constructor accepts as parameters the number of students and the number of exams, then builds an appropriately sized two-dimensional array, rather than receiving a preinitialized two-dimensional array as it does now. Set each element of the new two-dimensional array to -1 to indicate that no grade has been entered for that element. Add a setGrade method that sets one grade for a particular student on a particular exam. Modify class GradeBookTest of Fig.7.17 to input the number of students and number of exams for the GradeBook and to allow the instructor to enter one grade at a time.
Fig.7.16
Fig.7.17
I // Fig. 7.16: GradeBook.java // GradeBook class using a two-dimensional array to store grades. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 III 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 public class GradeBook { private String courseName; // name of course this grade book represents private int [] [] grades; // two-dimensional array of student grades 148 149 } // two-argument constructor initializes courseName and grades array public GradeBook (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 output Grades(); // call methods getMinimum and getMaximum System.out.printf("%n%s %d%n%s %d%n%n", } } // find minimum grade public int getMinimum() { // assume first element of grades array is smallest int lowGrade = grades [0] [0]; // output grade distribution chart of all grades on all tests outputBarChart (); "Lowest grade in the grade book is", getMinimum(), "Highest grade in the grade book is", getMaximum()); // loop through rows of grades array for (int[] studentGrades : grades) { } } // find maximum grade public int getMaximum() { // assume first element of grades array is largest int highGrade = grades [0] [0]; return lowGrade; // loop through columns of current row for (int grade studentGrades) { // if grade less than lowGrade, assign it to lowGrade if (grade lowGrade) { lowGrade grade; // loop through rows of grades array for (int[] student Grades grades) { // loop through columns of current row for (int grade studentGrades) { // if grade greater than highGrade, assign it to highGrade if (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]; } highGrade) { highGrade grade; // for each grade in GradeBook, increment the appropriate frequency for (int[] studentGrades grades) { for (int grade studentGrades) { } } } // for each grade frequency, print bar in chart for (int count = 0; count < frequency.length; count++) { // output bar label ("00-09: ", ..., "90-99: ", "100: ") if (count==10) { System.out.printf("%5d: ", 100); } else { ++frequency [grade / 10]; } System.out.printf("%02d-%02d: ", count* 10, count* 10 + 9); } // print bar of asterisks for (int stars = 0; stars frequency [count]; stars++) { System.out.print("*"); } // output the contents of the grades array public void outputGrades () { System.out.printf("The grades are: %n%n"); System.out.print(" System.out.println(); "); // align column heads // create a column heading for each of the tests for (int test = 0; test < grades [0] .length; test++) { System.out.printf("Test %d ", test + 1); } System.out.println("Average"); // student average column heading // create rows/columns of text representing array grades for (int student = 0; student < grades.length; student++) { System.out.printf("Student %2d", student + 1); 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);
Step by Step Answer:
To modify the GradeBook class according to your specifications we need to perform the following steps 1 Change the constructor to accept the number of ...View the full answer
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Students also viewed these Computer science questions
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Start of Payroll Project 7-3a October 9, 20-- No. 1 The first payroll in October covered the two workweeks that ended on September 26 and October 3. This payroll transaction has been entered for you...
-
The first payroll in October covered the two workweeks that ended on September 26 and October 3. This payroll transaction has been entered for you in the payroll register, the employees' earnings...
-
Match the following ratios with the appropriate formula. Ratio or Rate Formula a. Income from operations Interest expense Acid-test Total liabilities Stockholders' equity Current b. Net income-...
-
(Computation of Basic and Diluted EPS) The information below pertains to Barkley Company for 2010. Net income for the year.................................................................$1,200,000...
-
Lockheed, one of the largest defense contractors in the United States, reported EBITDA of $1,290 million in a recent financial year, prior to interest expenses of $215 million and depreciation...
-
Explain which theory you believe best explains motivation and why.(p. 93)
-
Refer to the information in Exercise 7. In Exercise 7 Required a. Assume that Demron estimates uncollectible accounts as 2% of receivables. Prepare the adjusting entry required on December 31, 2014,...
-
Setting 3 financial goals shortterm, moderate and longterm specific about the goal, that it is measurable, something that is achievable, realistic, and that you set a specific timeline
-
Modify Fig.7.13 to deal a five-card poker hand. Then modify class DeckOfCards of Fig.7.12 to include methods that determine whether a hand contains a) A pair b) Two pairs c) Three of a kind (e.g.,...
-
In the AccountTest class of Fig.7.9, method main contains six statements (lines 1112, 1314, 2627, 2829, 3839 and 4041) that each display an Account objects name and balance. Study these statements...
-
Sketch the graph of the function. g(t) = |1 - 3t|
-
What are the different types of drones?
-
What are the applications of drones?
-
What are the various protocols in telecom domain?
-
What are the various types of routing protocols?
-
For all the benefits they bring to business, social media and other communication technologies have created a major new challenge: responding to online rumors and attacks on a company's reputation....
-
In a double elimination softball tournament consisting of n teams, a team is eliminated when it loses two games. At most, how many games are required to complete the tournament?
-
A simple random sample of 220 university students were asked what pasta they usually order and with which sauce. The preferences of these respondents are summarised below: Sauce Bolognese Pasta...
-
Let T be a complete binary tree such that position p stores an element with key f (p), where f (p) is the level number of p (see Section 8.3.2). Is tree T a heap? Why or why not?
-
At which positions of a heap might the largest key be stored?
-
Give an example of a worst-case sequence with n elements for insertion-sort, and show that insertion-sort runs in (n 2 ) time on such a sequence.
-
Describe several common sources of yardstick data that you can use as bases for developing forecast assumptions
-
Green Lawn Company sells garden supplies. Management is planning its cash needs for the second quarter. The following information has been assembled to assist in preparing a cash budget for the...
-
eBook Question Content Area Comparison of Methods of Allocation Duweynie Pottery, Inc., is divided into two operating divisions: Pottery and Retail. The company allocates Power and General Factory...
Study smarter with the SolutionInn App