Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

friendliness and sincerity;

Answered: 1 week ago