412,878 views
11 votes
11 votes
Code an operation class called ArrayComputing that will ask user to enter a serials of integers with a loop until -99 is entered and after the input it will keep and display the greatest, the least, the sum and the average of the data entries (-99 is not counted as the data). And code a driver class called ArrayComputingApp to run and test the ArrayComputing class, separately.

Must use required/meaningful names for fields, variables, methods and classes.
Must use separate methods to perform each of specified tasks as described.
Must document each of your source code

User Daniel Wehner
by
3.3k points

1 Answer

16 votes
16 votes

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;

}

}

Code an operation class called ArrayComputing that will ask user to enter a serials-example-1
User Sander Smith
by
2.8k points