Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addNumber(int number) {
- number = this.sum + number;
- this.sum = number;
- this.count++;
- }
- public int sum() {
- return this.sum;
- }
- public void evens(int number) {
- if (number % 2 == 0) {
- this.sum = number + this.sum;
- }
- }
- public int evenT() {
- return this.sum;
- }
- public void odds(int number) {
- if (number % 2 != 0) {
- this.sum = number + this.sum;
- }
- }
- public int oddsT() {
- return this.sum;
- }
- public int getCount() {
- return this.count; // write code here
- }
- public double average() {
- if (this.count == 0) {
- return 0;
- } else {
- return (double) this.sum / this.count;
- }
- }
- }
- import java.util.Scanner;
- public class MainProgram {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Statistics statistics = new Statistics();
- Statistics even = new Statistics();
- Statistics odd = new Statistics();
- {
- System.out.println("Enter numbers: ");
- while (true) {
- int input = Integer.valueOf(scanner.nextLine());
- if (input == -1) {
- break;
- }
- statistics.addNumber(input);
- even.evens(input);
- odd.odds(input);
- }
- System.out.println("Sum: " + statistics.sum());
- System.out.println("Sum of even numbers: " + even.evenT());
- System.out.println("Sum of odd numbers: " + odd.oddsT());
- // System.out.println("Sum of odd numbers: " + odd);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement