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
Papessa [141]
3 years ago
7

Write a full class definition for a class named Averager, and containing the following members: An data member named sum of type

integer. An data member named count of type integer. A constructor with no parameters. The constructor initializes the data members sum and the data member count to 0. A function named getSum that accepts no parameters and returns an integer. getSum returns the value of sum. A function named add that accepts an integer parameter and returns no value. add increases the value of sum by the value of the parameter, and increments the value of count by one. A function named getCount that accepts no parameters and returns an integer. getCount returns the value of the count data member, that is, the number of values added to sum. A function named getAverage that accepts no parameters and returns a double. 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 data members to double prior to performing the division).
Computers and Technology
1 answer:
RUDIKE [14]3 years ago
7 0

Answer:

//program in java.

import java.io.*;

class Averager {

   public static int sum;

   public static int count;    

   //constructor to initialize values

   Averager(){

       sum = 0;

       count = 0;

   }

   //Method to return Sum

   public static int getSum(){

       return sum;

   }

   //Method to add the value passed in parameter

   public static void add(int num){

       sum=sum+num;

       count=count+1;

   }

   //Method to return Count

   public static int getCount(){

       return count;

   }

   //Method to return Average

   public static double getAverage(){

//type casting is used

       return (double) sum / (double) count;

   }      

   //User Driven Input method to run the program

public static void main (String[] args)throws IOException {

    //Using BufferedReader class for reading input

    InputStreamReader x = new InputStreamReader(System.in);

    BufferedReader inp = new BufferedReader(x);

    int n;

    do{

 System.out.println("Enter your choice");

 System.out.println("1.getSum()");

 System.out.println("2.add()");

 System.out.println("3.getCount()");

 System.out.println("4.getAverage()");

 System.out.println("5.Exit");

 n=Integer.parseInt(inp.readLine());

 switch(n)

 {

     case 1 : int s = getSum();

              System.out.println("The Sum is " + s);

              break;

     case 2 : System.out.println("Enter the number to add");

              int num;

              num=Integer.parseInt(inp.readLine());

              add(num);

              break;

     case 3 : int c = getCount();

              System.out.println("The Count is " + c);

              break;

     case 4 : double avg = getAverage();

              System.out.println("The Average is " + avg);

              break;

     default : break;

 };

    }while(n!=5);

    System.out.println("Exiting");

}

}

Explanation :

Average() constructor is used for initialization. Method getSum() will return the value of sum. Method getCount() will return the count and method getAverage() will return the average. The average will be of double type. User driver input is designed to call the methods as and when required.

Input:

Enter your choice

1.getSum()

2.add()

3.getCount()

4.getAverage()

5.Exit

1

Output:

The Sum is 0

You might be interested in
What type of websites, which let users share personal stories and photos, became popular in the 2000s?.
Lina20 [59]

Answer:

MMORPGS was a type of website that let users share their stories and pics across the world wide web

Explanation:

8 0
3 years ago
When emergency changes have to be made to systems, the system software may have to be modified before changes to the requirement
goblinko [34]

Answer:

The Agile model

Explanation:

We can point out that this is all about the software development lifecycle model. In the software developmental lifecycle, the agile model is the most suited model that can be used to bring changes as per the requirement.

It is the model that provides huge flexibility as the changes can be made to the software even if the application is running. Moreover, this model follows documentation regarding the process of bringing the changes to the software. And even the new changes should pass the quality assurance test in order to go to the production phase.

What this does is that it actually ensures that your application is fit and is consistent to handle and perform operations.

5 0
3 years ago
Why do meteorologists use data such as temperature, wind speed, and air
Tresset [83]

Answer:

b

Explanation:

3 0
3 years ago
Which three elements form a well-dimensioned drawing?
laiz [17]

Answer:

I think its D

lines graphics and symbols

8 0
3 years ago
What is the term for an individual who evaluates website statistics to determine the site’s effectiveness?
Sati [7]

Answer:

Web site analyst

Explanation:

Website analyst main goal is to gather data from website and based on that data take decision to improve website design, user experience or content to improve user experience. More over on the basis of data gathered from website they design different marketing strategist for the organization.

4 0
4 years ago
Other questions:
  • Mrs. Dunn shows her students a data range, which has been named "Goals,” covering cells A14 to A25. She tells her students that
    9·1 answer
  • You are configuring a wireless network with two wireless access points. Both access points connect to the same wired network. Yo
    10·2 answers
  • What is the term for individual computers and devices that are connected to a network?
    14·1 answer
  • In filmmaking, who is ultimately responsible for the creative process?
    15·1 answer
  • Read the following code: x = currentWeight print(x - 20) What value will this code calculate?
    8·1 answer
  • Suppose we want to design a combinational logic block that accepts a 4 bit Binary number as input. Let the most significant bit(
    14·1 answer
  • Complete the sentence. Use a ___ ___ (2 words) to find a website's URL based on keywords you specify.​
    15·1 answer
  • 12. Why is it so important to pay attention to your digital reputation?
    14·1 answer
  • What I Can Do
    15·1 answer
  • A _____ consists of horizontal bars, connected with arrows that indicate task dependencies.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!