Week 10 exercise 30 container

253 views
Skip to first unread message

allan...@googlemail.com

unread,
Sep 17, 2015, 10:18:50 AM9/17/15
to mooc.fi
Hi,

I'm having problems with week 10 exercise 30 Container.

*Explain your problem here in English or Finnish*

I'm getting the following error on this, now either i'm being really dumb and i understand this wrong or the greatest fluctuation is indeed 9?

check code
mh = new ContainerHistory();
mh.add(5.0);
mh.add(4.0);
mh.add(7.0);
mh.add(3.0);
mh.add(12.0);
mh.add(3.0);mh.greatestFluctuation()  expected:<11.0> but was:<9.0>


Best regards
Allan


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

ljleppan

unread,
Sep 21, 2015, 2:57:04 AM9/21/15
to mooc.fi, allan...@googlemail.com
Hi,

It seems the textual error is out of sync with the actual test. In the actual test code, the number added before 12 is 1, not 3. I've made a note of this and the error message will be fixed sometime in the future.

In any case, you have a problem with your greatestFluctuation() method, in that it returns an incorrect value. You should try it out with [2.0, 5.0, 10.0, 12.0, 8.0, 14.0, 11.0, 10.0, -2.0, -3.0, 7.0, 7.0, -3.0], which should return 12. Your code returns 10.

Right now, your code always returns the difference between the last two numbers as the greatest fluctuation. To correct this error, you should change your code so that as you move along the numbers, you remember the greatest fluctuation encountered so far, updating it if you encounter an even bigger fluctuation.

-Leo
Reply all
Reply to author
Forward
0 new messages