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

Report Software 1

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)
20 views3 pages

Report Software 1

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy