I have some java code that is supposed to be in the form of classes, take input as numbers, get the average, sum, and count of the numbers entered, and it seems to work for the most part except when actually trying to input values from the main method. How can I adjust this so that the program is able to accept the values?
public class AverageCalculator {
private int sumOfNumbers ;
private int countOfNumbers ;
AverageCalculator() { // no arg constructor
sumOfNumbers = 0;
countOfNumbers = 0;
}
void add(int newNum) { // adds a number to the average calculator
this.sumOfNumbers = newNum + sumOfNumbers;
countOfNumbers++;
}
int getSum() { // returns the sum of all the numbers added to average calculator
return sumOfNumbers;
}
int getCount() {// returns the number of numbers added to the average calculator
return countOfNumbers;
}
double getAverage() {// returns the average of all numbers added to average calculator
double average = this.sumOfNumbers / this.countOfNumbers;
return average;
}
}
class AverageCalculatorMain {
public static void main(String[] args) {
AverageCalculator average = new AverageCalculator(4); //with one value
AverageCalculator average = new AverageCalculator(3,4,5)//with three values
System.out.println("The average is " + average.getAverage() + " the sum is " + average.getSum()
+ " the count of numbers is " + average.getCount());
}
}