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]
2 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]2 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
The repeated use of electronic communications, such as chat rooms and email, to seek out, harass, or frighten someone is called
pickupchik [31]

Answer:

CyberStalking

Explanation:

Stalking over the internet carried out . it target individuals or organisation to stalk and harass

5 0
3 years ago
Your principal has hired you to design a drone that can monitor students in the hallways. Before you brainstorm design ideas, yo
torisob [31]
It’s gonna be Answer B because all the other answers just sound silly
8 0
3 years ago
Read 2 more answers
How will you identify a file type on your computer?
Andru [333]

You use the extension on the end of the file to tell you the type of a file

The extension is the .whatever in the name of the file

5 0
2 years ago
A template slide that controls the formatting of all other slides in the presentation is called a _________.
PtichkaEL [24]

Answer:

the answer is slide master

7 0
2 years ago
You don’t design new software. Instead, you work with software that already exists to be sure that it keeps running smoothly. Wh
Arada [10]

Answer:

Explanation:

If you are developing software products, run complex projects, you should ... All the same, to make the right choice of an SDLC methodology, you ... Generally, there are stages involved in all the different methodologies. ... You will therefore have to keep both the old and new systems running for some time.

5 0
2 years ago
Read 2 more answers
Other questions:
  • Write a program that takes two ints as input from the keyboard, representing the number of hits and the number of at bats for a
    10·1 answer
  • Proxy data:
    12·1 answer
  • When transporting data from real-time applications, such as streaming audio and video, which field in the ipv4 header can be use
    14·1 answer
  • A type of wireless local area network technology​
    7·2 answers
  • Which of the following is NOT one of the modules of a typical Decision Support System (DSS)? Select one: a. Customer information
    14·2 answers
  • Why is it so important to have employees who can critically think?
    7·2 answers
  • Word documents contain how many sections by default?
    9·1 answer
  • WHAT IS A GOOD APP FOR REMOVING VIRUSES AND IT YOU DONT HAVE TO PAY MUCH FOR IT ????? PLEASE HELP ME
    8·2 answers
  • If any one has mincraft on ps4 bedrock we can finish building a BIG city world all we need to put is a shop and money dispensers
    8·2 answers
  • In what way, if any, are problems related to conflicts? Problems and conflicts are the same thing. Problems and conflicts are th
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!