Mohamed Nageeb/
20196575/ a1/
System
CES
Software Report
public class AverageCalculator { 1
private int sum;
private int count;
private float avg;
public AverageCalculator() {
sum = 0;
count = 0;
avg = 0.0f;
public void add(int number) {
sum += number;
count++;
public void output() {
avg = sum / count;
System.out.println("Average: " + avg);
}
}
import java.util.Scanner;
public class AverageCalculatorDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int evenSum = 0;
int evenCount = 0;
int oddSum = 0;
int oddCount = 0;
System.out.print("Enter a number: ");
int number = scanner.nextInt();
while (number != 0) {
if (number % 2 == 0) {
evenSum += number;
evenCount++;
} else {
oddSum += number;
oddCount++;
System.out.print("Enter a number: ");
number = scanner.nextInt();
AverageCalculator evenAverageCalculator = new AverageCalculator();
evenAverageCalculator.add(evenSum);
evenAverageCalculator.output();
AverageCalculator oddAverageCalculator = new AverageCalculator();
oddAverageCalculator.add(oddSum);
oddAverageCalculator.output();
scanner.close();