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
A(n) ________ is a chart based on PivotTable data.
Mrrafil [7]
Well since it’s a chart based on a PivotTable prettyyyy sure it’s gonna be a PibltChart
7 0
3 years ago
What is a gamer?
mixer [17]

Answer:

It is <em>definitely </em>D.

Explanation:

I am a gamer myself so this question is easy for me. It's slim to none to be wrong when you view my answer!!!

7 0
2 years ago
1. an image can be stored either in a vector graphic file or in a bitmap file true or false
lions [1.4K]

Answer:

1 true 2 true 3 false 4 true

Explanation:

7 0
3 years ago
Who wants to be my tutor?
anzhelika [568]

Answer:

i would but im not big brain

Explanation:

8 0
3 years ago
Read 2 more answers
As text is typed in the _____ text box, a drop-down list displays options for completing the action, displaying information on t
pickupchik [31]

Answer:

Excel Help

Explanation:

Press F1 key to open the excel help window

Or you can also click the excel help button to launch the help window.

Type for whatever you are seeking help for and you will notice suggestions as you type something. These suggestions include online and offline results. If there are too many results then try searching offline it will narrow down the results.

After typing the text and hitting enter, the excel help returns several related topics on the searched query. You can browse through these topics and get help from excel.

5 0
3 years ago
Other questions:
  • What are the first and the last physical memory addressesaccessible using
    10·1 answer
  • What does PHP stand for?
    9·2 answers
  • Which of the following has allowed computers to have more memory capabilities without making them extremely expensive Virtual me
    9·1 answer
  • -The following type of Access form allows to see multiple records in an Excel-like arrangement of data fields:
    14·1 answer
  • In no less than two paragraphs, explain the risks and compliance requirements of moving data and services into the cloud.
    11·1 answer
  • 4.17 LAB: Varied amount of input data ( C++)
    5·1 answer
  • I need the answer to life. I cant live without my POGCHAMPS!
    11·2 answers
  • To create a program in Scratch, you need to think systematically about the order of steps. This is known as
    11·1 answer
  • What instructions would a computer have the hardest time completing correctly
    12·1 answer
  • The act of using computer equipment to “break into” the computer systems of others?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!