Answer:
Step-by-step explanation:
The following is written in Java and creates the ArrayComputing class. It uses the constructor to create the infinite loop that only breaks when the user enters a -99. After every input number it goes adding the correct values to the variables. Once it is done the user can call any of the getter methods to get the variable values as well as calculate the average.
import java.util.Scanner;
class ArrayComputingApp {
public static void main(String[] args) {
ArrayComputing arrayComputing = new ArrayComputing();
System.out.println("Average: " + arrayComputing.getAverage());
System.out.println("Greatest: " + arrayComputing.getGreatest());
System.out.println("Least: " + arrayComputing.getLeast());
System.out.println("Sum: " + arrayComputing.getSum());
}
}
class ArrayComputing {
int greatest, least, sum, average;
int count = 0;
Scanner in = new Scanner(System.in);
public ArrayComputing() {
while (true) {
System.out.println("Enter a number or -99 to exit: ");
int num = in.nextInt();
if (num == -99) {
break;
}
if (num > this.greatest) {
this.greatest = num;
}
if (this.count == 0) {
this.least = num;
} else {
if (num < this.least) {
this.least = num;
}
}
this.sum += num;
this.count += 1;
}
}
public int getAverage() {
this.average = sum / count;
return this.average;
}
public int getGreatest() {
return greatest;
}
public int getLeast() {
return least;
}
public int getSum() {
return sum;
}
}