1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Kisachek [45]
3 years ago
6

Write a class named Averager containing: An instance variable named sum of type integer, initialized to 0. An instance variable

named count of type integer, initialized to 0. A method named getSum that returns the value of sum. A method named add that accepts an integer parameter. The value of sum is increased by the value of the parameter and the value of count is incremented by one. A method named getCount that accepts no parameters. getCount returns the value of the count instance variable, that is, the number of values added to sum. A method named getAverage that accepts no parameters. getAverage returns the average of the values added to sum. The value returned should be a value of type double (and therefore you must cast the instance variables to double prior to performing the division).
Computers and Technology
1 answer:
vladimir1956 [14]3 years ago
3 0

Answer:

The answer to this question can be given as:

Class definition:  

public class Averager  //define class Average.

{

private int sum = 0;

 //define variable sum.

private int count = 0;

 //define variable count.  

public int getSum() //define function getSum().

{

return sum;  //return value.

}

public void add(int x)

//define function add().

{

sum = sum + x;   //calculate sum

count=count+1; //increase value of count.

}

public int add(int x)

 //define function add().

{

return count;  //return value.

}

public double getAverage()  //define function getAverage().

{

return (double)sum/count;  //return value

}

}

Explanation:

The above class definition can be described as:

  • In the above class definition first we define a class that is " Averager". In this class we define two integer variable  that is "sum and count"  and assign a value that is 0. Then we define a functions :
  • First we define getSum() function in this function we does not pass any value and the return type of this function is int that will return an integer value.
  • Then we define add() function we use this function two times but both functions have different from each other.  
  • In first time implementation, we define this function and the return type of this function is void which means it does not return any value. In this function, we calculate the sum value and increase the value of the count variable by 1.  
  • In second time implementation, we define this function and the return type of this function is int which means it will return a value. In this function, we will return the count variable value.
  • At the last, we define a getAverage() that calculates the average of the added values in the sum variable and returns its value.
You might be interested in
AYUDAAA ESPARA HOYYY
DIA [1.3K]

Answer:

what?

Explanation:

8 0
3 years ago
Read 2 more answers
Timelines show
Aloiza [94]
A. the order of events...
hope this helps!
4 0
3 years ago
Read 2 more answers
Please help with this coding question
snow_tiger [21]
Answer: the variable called errors is tested to see if it is less than it equal to 4
8 0
3 years ago
Read 2 more answers
What is the best thing about Tuesday’s in general? Why?
Stolb23 [73]

Answer:

tbh I really don't know what you mean

4 0
4 years ago
HELP PLS!!! In a presentation, what is layout?
bija089 [108]
A plan about how to do it
3 0
3 years ago
Read 2 more answers
Other questions:
  • Why people needs soft skills in the era of high technology.
    13·1 answer
  • ____ are systems in which queues of objects are waiting to be served by various servers
    5·1 answer
  • How many frequencies does a full-duplex qam-64 modem use?
    8·2 answers
  • Multiple choice
    9·2 answers
  • Which statement best describes multimedia
    14·1 answer
  • SONET: is a standard for optical transmission that currently operates at Terabit per second speeds is almost identical to the IT
    7·1 answer
  • You are a database administrator. Chantelle comes to you asking for help on how to access all the data in one row of the databas
    11·1 answer
  • Explain about third generation of computer​
    5·1 answer
  • What is a zerø-day exploit? No go.ogle >:(
    10·1 answer
  • 20
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!