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...
-
A 3-m-long steel rod (k = 43 W/(mK), = 1.17 \ 105 m2/s) is initially at 20C and insulated completely except for its end faces. One end is suddenly exposed to the flow of combustion gases at 1000C...
-
In a single stage steam turbine saturated steam at 10 bar is supplied through a convergent divergent steam nozzle of \(20^{\circ}\) angle. The mean blade speed is \(400 \mathrm{~m} / \mathrm{s}\)....
-
One of your acquaintances notes, This whole subject of differential costing is easy; variable costs are the only costs that are relevant. How would you respond?
-
Zachary Corporation paid one of its sales representatives $8,500 during the month of March. The rep is paid a base salary plus $14 per unit of product sold. During March, the rep sold 170 units....
-
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...
-
Eagle Sports Products (ESP) is considering issuing debt to raise funds to finance its growth during the next few years. The amount of the issue will be between $35 million and $40 million. ESP has...
-
Performers in the Rock and Roll Hall of Fame From its founding through 2015, the Rock and Roll Hall of Fame has inducted 303 groups or individuals, and 206 of the inductees have been performers while...
-
A project has an NPV of $\$ 3,444$ and a standard deviation of $\$ 1,780$. What is the probability that NPV could be 0 or less?
-
In a high-speed coating system, the mass flowrate of polyester powder has an average value of $120 \mathrm{gm} / \mathrm{sec}$. There is a $75 \%$ probability the flowrate is between $110 \mathrm{gm}...
-
A young entrepreneur, Ima Newby, has been working in the health information technology field for a number of years, both as a developer and user of electronic health records (EHRs) for dental...
-
What is the difference in the reinvestment assumption of NPV and IRR, and what might be the limitation of those strategies in selection of capital equipment?
-
a. Average back the decision tree below, supplying expected monetary values for points A through E. b. One of your fellow managers is worried that there are no probabilities given for the branches...
-
Planning: Creating an Audience Profile; Collaboration: Team Projects. Compare the Facebook pages of three companies in the same industry. Analyze the content on all available tabs. What can you...
-
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.
-
An investment banker is analyzing two companies that specialize in the production and sale of candied yams. Cullumber Yams uses a labor-intensive approach, and Ivanhoe Yams uses a mechanized system....
-
Use the DESMOS software to complete the following questions. 1. Complete the table below by graphing using DESMOS software. Vertex Direction of opening Maximum/ Minimum Axis of symmetry 2 y = x - 5 y...
-
Multiply and simplify: (2x-27) (2x+27)
Study smarter with the SolutionInn App