NumberStatistics 79.4: MANY SUMS

148 views
Skip to first unread message

jennda...@gmail.com

unread,
Nov 22, 2016, 10:12:12 PM11/22/16
to mooc.fi
Hi,

I'm having problems with week EXERCISE 79.4: MANY SUMS. I'm 89% already.

I'm getting this errors:

NumberStatistics1Test evenAndOdd
With input 2 4 1 6 -1 your program should print sum of even: 12, now it printed: sum of even: 0

and

NumberStatistics2Test ObjectsUsed
You should use NumberStaticstics objects to track the sum of input and also the sum of even and odd numbers in the input Objects should be created in the following orded: The first is used to track sum of all given numbers The second takes care of even numbers and the third the odd numbers. NOTE: do not add other values to objects that user entered Remember: number -1 which is used to stop the program shouldn't be included in the statistics! Error happened with user input 2 -1 more info: java.lang.AssertionError: Unexpected constructor call NumberStatistics(0): NumberStatistics(): expected: 3, actual: 0


Best regards


Supported languages are English and Finnish

Please use our build in TMC Pastebin when asking questions related to your code  
 
TMC Plugin has built-in code sharing feature. 
In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it to your message.  

You may use our web interface to share code snippets: http://paste.mooc.fi

b...@slb.coop

unread,
Nov 24, 2016, 10:09:50 AM11/24/16
to mooc.fi, jennda...@gmail.com
I got 95% on the same question, but the same error. I couldn't see the link, as I think you have to be an administrator, so I don't know if your code is different to mine.

FAIL: NumberStatistics2Test ObjectsUsed

You should use NumberStaticstics objects to track the sum of input and also the sum of even and odd numbers in the input
Objects should be created in the following orded:
  The first is used to track sum of all given numbers 
  The second takes care of even numbers and the third the odd numbers. 
NOTE: do not add other values to objects that user entered
      Remember: number -1 which is used to stop the program shouldn't be included in the statistics!
Error happened with user input 2 -1
more info: java.lang.AssertionError: 
  Unexpected method call NumberStatistics.amountOfNumbers():
    NumberStatistics.sum(): expected: 1, actual: 0


FWIW my code was:

Scanner reader = new Scanner(System.in);

        NumberStatistics allNums = new NumberStatistics();
        NumberStatistics evenNums = new NumberStatistics();
        NumberStatistics oddNums = new NumberStatistics();

        System.out.println("Type numbers:");
        int userEntry = reader.nextInt();
        while (true) {
            if (userEntry == -1) {
                break;
            }
            allNums.addNumber(userEntry);
            if (userEntry % 2 == 0) {
                evenNums.addNumber(userEntry);
            } else {
                oddNums.addNumber(userEntry);
            }
            userEntry = reader.nextInt();

        }

        System.out.println("Amount: " + allNums.amountOfNumbers());
        System.out.println("sum: " + allNums.sum());
        System.out.println("sum of even: " + evenNums.sum());
        System.out.println("sum of odd: " + oddNums.sum());

I hope someone can point out the problem!

Thanks 
Reply all
Reply to author
Forward
0 new messages