Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 3: Quiz Average Calculator (this exercise may be completed outside of class and signed off at the next lab period) This exercise is to
Exercise 3: Quiz Average Calculator (this exercise may be completed outside of class and signed off at the next lab period) This exercise is to implement a special kind of calculator. This calculator will keep track of the total of all quiz scores attained by a student, and the total number of quizzes taken, and will then return the average score for those quizzes The class, named QuizCalculator, will have attributes for The student's name (a string) The total number of quizzes taken (initially zero) . . The sum of all the quiz scores taken so far (initially zero) It will have one constructor, that expects the student's name as the only parameter. It wil copy this into the name attribute and set the totals to zero It will have three methods .A method: public void addscore (double newScore) which will add the newScore into the sum of all quiz scores and increment the total number of quizzes taken by one .A virtual accessor: public double getAverage) which will return the quiz average for the student (sum of all scores / total number of quizzes). Remember: a virtual accessor has NO actual ttribute variable, but is calculated on the fly when you get it. .A method public String tostring ) which will return the student's name and average as in William Johnson quiz average: 92.50 NOTE: the tostring method should call the getAverage method to obtain the quiz average for the student. Also write a test class with the main program in it to test this out for at least two students Each student should have at least 3 quizzes to average. The student averages should be printed using tostring () Special Note You should print the quiz averages to exactly two decimal places. To do this, you will use the format method of the string class as in String. format("6.2f", value) This returns a string which is the value formatted according to the %6.2f format specifier. The value must be a double. The format specifier says to format the value as a 6-character string with 2 digits to the right of the decimal point. So, if the value is a student's quiz average (as returned by getAverage(), it is formatted as follows: This shows a string 6 spaces long with a decimal point and two places to the right of the decimal point. The 'D's just represent digits in the string. If the value is 85.63452 the result of String.format ("$6.2f", value) will be " 85.63". Since there are only two digits to the LEFT of the decimal point, the first digit will be replaced with a space. Digits after the 1st two to the RIGHT of the decimal point will be truncated (actually, rounded to two places) SO the %6.2 f is a 'picture' of what the value will look like and the value is then placed in the picture, around the decimal point. NOTE: the 6 (6 characters) INCLUDES the decimal point. Why 6??? Because after the decimal point (1 space) and two digits to the right of the decimal point (2 spaces) this leaves 3 spaces to the left of the decimal point. A perfect score of 100.00 requires 3 spaces to the left of the decimal point.. total 6 spaces
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started