Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

A manufacturer wants to keep track of the average of the ratings that have been submitted for an item using a running average. The algorithm for calculating a running average differs from the standard algorithm for calculating an average, as described in part (a). A partial declaration of the RunningAverage class is shown below. You will write two methods of the RunningAverage class.

(a). Write the method updateAverage, which updates the RunningAverage object to include a new rating. To update a running average, add the new rating to a calculated total, which is the number of ratings times the current running average. Divide the new total by the incremented count to obtain the new running average.

(b) Write the processNewRatings method, which considers num new ratings for inclusion in the running average. A helper method, getNewRating, which returns a single rating, has been provided for you. The running average must only be updated with ratings that are greater than or equal to zero. Ratings that are less than 0 are considered invalid and are not included in the running average. The processNewRatings method returns the number of invalid ratings. See the table below for three examples of how calls to processNewRatings should work.image text in transcribedimage text in transcribed

3. SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. A manufacturer wants to keep track of the average of the ratings that have been submitted for an item using a running average. The algorithm for calculating a runn average differs from the standard algorithm for calculating an average, as described in part (a). A partial declaration of the RunningAverage class is shown below. You will write two methods of the RunningAverage class. public class RunningAverage { /** The number of ratings included in the running average. */ private int count; /** The average of the ratings that have been entered. */ private double average; // There are no other instance variables. /** Creates a RunningAverage object. * Postcondition: count is initialized to 0 and average is * initialized to 0.0. */ public RunningAverage () { /* implementation not shown */ } /** Updates the running average to reflect the entry of a new * rating, as described in part (a). */ public void updateAverage (double newval) { /* to be implemented in part (a) */ } /** Processes num new ratings by considering them for inclusion * in the running average and updating the running average as * necessary. Returns an integer that represents the number of * invalid ratings, as described in part (b). * Precondition: num > 0 */ public int processNewRatings (int num) { /* to be implemented in part (b) */ } /** Returns a single numeric rating. */ public double getNewRating () { /* implementation not shown */ } } (a) Write the method updateAverage, which updates the RunningAverage object to include a new rating. To update a running average, add the new rating to a calculated total, which is the number of ratings times the current running average. Divide the new total by the incremented count to obtain the new running average. For example, if there are 4 ratings with a current running average of 3.5, the calculated total is 4 times 3.5, or 14.0. When a fifth rating with a value of 6.0 is included, the new total becomes 20.0. The new running average is 20.0 divided by 5, or 4.0. Complete method updateAverage. /** Updates the running average to reflect the entry of a new * rating, as described in part (a). */ public void updateAverage (double newval) Please respond on separate paper, following directions from your teacher. (b) Write the processNewRatings method, which considers num new ratings for inclusion in the running average. A helper method, getNewRating, which returns a single rating, has been provided for you. The running average must only be updated with ratings that are greater than or equal to zero. Ratings that are less than 0 are considered invalid and are not included in the running average. The processNewRatings method returns the number of invalid ratings. See the table below for three examples of how calls to processNewRatings should work

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

Step: 3

blur-text-image

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

=+applying to all or most employers and employees?

Answered: 1 week ago