0% found this document useful (0 votes)
27 views3 pages

Report Software 1

The document contains a Java program that calculates the average of even and odd numbers entered by the user. It includes a class 'AverageCalculator' for managing the sum and count of numbers, and a demo class that handles user input and displays the averages. The program continues to prompt for numbers until the user inputs zero.

Uploaded by

atatsalama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Report Software 1

The document contains a Java program that calculates the average of even and odd numbers entered by the user. It includes a class 'AverageCalculator' for managing the sum and count of numbers, and a demo class that handles user input and displays the averages. The program continues to prompt for numbers until the user inputs zero.

Uploaded by

atatsalama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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();

You might also like