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
Berat wants to compare images of what the streets of New York City looked like one hundred years ago to now. Which of the follow
Vesnalui [34]

Answer:

I think the answer would be D.

7 0
3 years ago
Read 2 more answers
A(n) monitoring vulnerability scanner is one that listens in on the network and determines vulnerable versions of both server an
Tom [10]

Answer: Passive

Explanation: Passive scanning is the process that scans the possibility of the risk that can arise while data is received starting port to the destination. It does the scanning between the server and the client software to define vulnerability .

It cannot work in those network which don't persist the traffic.No false data that is present in the application is detected by it if the data is unclear.

5 0
3 years ago
Can someone write a 5 sentence summary about Virtual Assistants. Please. I'm in a rush. Personal problems.
Lyrx [107]
Virtual Assistants can be useful. Blind people can use them to be informed, browse the web, and learn new facts. They can make tasks quicker too. They can control things like your heater or air conditioner. But if one were to malfunction, it could take lives.
7 0
3 years ago
What is the most widely used operating system for mobile devices?
Alekssandra [29.7K]
Android, many phone brands use the Android OS. Unlike Apple, which is the only technology company with IOS.
8 0
3 years ago
What process sends ones and zeroes across network cables
sergejj [24]

Answer:

modulation

Explanation:

Modulation is the procedure of encoding data into electrical signals for transmission through a media. For transmission, binary information, denoted by a sequence of ones and zeros, should be translated to analog or digital electrical signals. The method converts data into electrical signals suited for transmission is known as modulation.  Digital modulation is the transmission of binary signals zeroes and ones.

5 0
2 years ago
Other questions:
  • Which of the following is the best definition of a workplace policy?
    13·2 answers
  • Helppppppppppppppppppp
    11·1 answer
  • A style manual can be described as
    11·2 answers
  • The blue bar across the top of the screen informs you of the Screen Title, or what step you are on.
    5·1 answer
  • If(moreDate == true)
    7·1 answer
  • Using existing algorithms as building blocks for new algorithms has all the following benefits EXCEPT
    12·1 answer
  • What is 3x10? PLZZZZZ
    11·1 answer
  • Which of the following statement is correct ? A . potential difference is measured by ammeter . B . The unit of potential differ
    9·1 answer
  • Write a function check_palindrome that takes a string as an input and within that function determines whether the input string i
    12·1 answer
  • Why do I keep getting points if I haven't answered anything? I don't want points.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!