Question: Write a class AverageCalculator . The purpose of a AverageCalculator object is to count, sum and average a series of numbers. The AverageCalculator class has

Write a class AverageCalculator. The purpose of a AverageCalculator object is to count, sum and average a series of numbers. The AverageCalculator class has the following specification: instance variable of type int for the running sum of numbers that have been given to the AverageCalculator instance variable of type int for the count of numbers that have been given to the AverageCalculator no argument constructor  AverageCalculator () a mutator method to add a number to the AverageCalculator void add(int newNum) an accessor method to return the sum of all the numbers added to the AverageCalculator int getSum() an accessor method to return the count, or number, of numbers added to the AverageCalculator int getCount() an accessor method to return the average of all the numbers added to the AverageCalculator note that the instance variables are int, and the return type of this method is double--be careful with the division operation. If no numbers have been added to the AverageCalculator object, return 0.
double getAverage()

Write a class, AverageCalculatorMain that contains a main method and does the following:

create a AverageCalculator object, add one number to the AverageCalculator (pick whatever value you wish), and print the sum, count and average of the AverageCalculator .

create another AverageCalculator object. Add three numbers to the AverageCalculator , and print the sum, count and average of the AverageCalculator .

Follow all instructions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!