It wasn't difficult for me to reference the Class's variable, and to assign it the variable passed as argument. My difficulty was to understand what it was asked of me to do with it from the description statement. I mistakenly thought it was to print the last known price, not to accumulate all the prices passed on each call.
Was it just me, or the statement wasn't really clear?
Thank you
Just clarifying: The purpose of the method is to add up EACH new apple_object price, and not to display the price of the last apple_object.
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Eric Larry
2 February 2023, 15:52
I invested 90% of my retirement payment on binary options with the mindset of getting it multiplied and enjoying a better retirement life. It was sweet and smooth from the start, withdrawals were easy and consistent until it got to a point I started to be denied withdrawals, I couldn't get my invested amount back not to talk of the bonuses. I contacted several lawyers but it was all a waste of time and money, they couldn't render an inch of help. God so good to my old self and family, I later met with a professional that helped get my money back from them, it was worth it to pay him 20% of the money. You can contact the professional on "shimomura@linuxmail.org" if you have found yourself in the same situation as me, I can assure he would be able to help you just as he helped me, you can give it a trial if you don't mind. You can also contact me personally on "ericlarry54@gmail.com" if you need more info from me. Binary options brokers shouldn't get away with this!
0
Emil Valentin Toma
3 February 2019, 01:45
Hi Fernando,
Actually printing out the "Apple.applePrice" (and not "apple1" and "apple2" prices) would sum up the results from applying consecutively the method "addPrice" for 2 instances (of the rise in price with 50, respectively 100). The addPrice method is embedded in both apple1 and apple2 objects. So when they are instantiated, apple1 will have the price calculated with applePrice = 50. But hey, applePrice variable will hang on with its new value, 50 (not zero) and this new value of 50 will be the entry point for the calculation of price for the next apple price, apple2. Although apple1 and apple2 are able to calculate the prices separately and even to sum their prices up in a classical sum operation, the exercise author specifically wants us to understand exactly that principle of variable inheritance when it's used in different objects. This is for applePrice being a "static" variable, which makes it possible to be shared across other classes of the same level and below.
As the author of exercise specifies in the "Conditions" file:
"5. The Apple class's addPrice method should increase the cost of apples by the passed-in value."
Keyword: passed-in. The vehicle transporting this passing-in, dynamic value is applePrice.
Hope this helped.
+6
Thomas
22 May 2019, 19:58
Great explanation !!
+1
Emil Valentin Toma
24 June 2019, 02:15
Thanks Thomas!
0
kapil
1 February 2019, 08:19
please attach your code with given requirement, to understand your question
0