SHOW ALL YOUR WORK. 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. You shouldn't write significant amounts of code that can be replaced by a call to one of these methods . 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. 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 */ } }
Pls answer part a and b accordingly. Read this first:
SHOW ALL YOUR WORK. 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. You shouldn't write significant amounts of code that can be replaced by a call to one of these methods .
A manufacturer wants to keep track of the average of the ratings that have been submitted for an item using a running average. The
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 */ }
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps