# Price of apples

• 4
• Locked
On the agrarian planet Appleside, the vast majority of inhabitants make most of their income selling the best apples on this side of the Galaxy to Federation merchant ships and visiting tourists. Let's enter a business relationship with an abstract buyer. Considering the fact that the season is ending and we must somehow survive the winter: write a method that raises the price of apples!
You can't complete this task, because you're not signed in.
jerry
Level 16 , Earth C-137, Thailand
4 August 2021, 09:37
WHY and HOW Apple.applePrice = 50 ? MY understanding: 1. applePrice = 0 2. apple1.addPrice(50); increase it to 50. // its literally ADDS price to our 0 3. apple2.addPrice(100); increase it to 150. // ADDS 100 to our new value. ` so its basically 2 actions: first, it takes 0 and add 50 from apple1 so its not 0 anymore but 50. second, to our 50 it adds value of apple2. the static thing was okay but "the formula" of this apple price took me 2 martian weeks to understand... ``correct me if u dare Hope u got it Brazzzer or SIS stay tuned ~btw do u want develop an app?
Elias Daniel Hung
Level 4 , Caracas
16 July 2021, 23:57
If I can, you can, if you don't understand I'll help you, the path is easier together ...
RUBEN CABRERA
Level 5 , Koxhausen, Germany
29 August 2021, 17:27
Hello Elias, I would like to understand more about static methods and static fields, I try to complete this task but I have some errors, I read some more documents even Java tutorial but I think I need more clearly explanation.
Aron
Level 14
30 June 2021, 19:13
As the applePrice variable is static meaning that it belongs to the Apple class not its instances. The instance Objects (apple & apple2) can access the static variable via the class name i.e Apple.applePrice
Mike Bayley
Level 4 , Fishponds, United Kingdom
3 August 2021, 20:25
Thank you Aron. This one was particularly confusing to me until I read your comment 🙃
Mateusz
Level 29 , Poland
21 August 2020, 12:37
Could anyone explain to me what the reason for making the addPrice method static is? Isn't it better to make it non-static? And similar question: why the class Apple is in the class Solution? Isn't it better to create the class Apple in a separate file and make it non-static?
Andrei
Level 41
4 September 2020, 12:03
Good question, maybe someone can answer!
Daniel
Level 9 , Vienna, Austria
4 May 2020, 00:41
I'll give you a hint. I hope you'll figure it out. "public static int applePrice = 0;" has to be called using the class name to be "seen" because it belongs to the Class (it's static):
``Apple.applePrice``
and "int applePrice" taken by the method is called simply like this:
``applePrice``
So, bottom line:
``initialized int applePrice + intTheMethodTakes = initialized int applePrice;``
or more simple
``initialized int applePrice += intTheMethodTakes;``
Liew
Level 10
16 April 2020, 03:53
very easy, you just need to know how to link to get the static variable, check out the lessons if you do not get it.
Gregory
Level 4 , Netherlands
26 January 2020, 07:15
super lost
Michael Scanlan
Level 4 , Kalispell, United States
26 January 2021, 23:43
Me too, I have no idea what the want with this one
Alec Jensen
Level 5 , Arlington, United States
20 December 2019, 17:58
definitely confused when this did not meet all requirements. The very last requirement is the one it did not pass. "addPrice method should increase the cost of apples by the passed-in value." any help?
Andrei
Level 41
4 September 2020, 11:57
I think the sum displayed should be 150.
Brandon Nicolle
17 August 2019, 19:40
I went through this code and it's definitely helping me understand some of the class functions. Can I please get a simple explanation on why += gives me 150 but = gives me 100? Why does the += operator call both of them?
Justin Smith
Level 8 , United States
20 August 2019, 04:58
The += operator adds whatever value to the existing value, whereas the = will overwrite completely.
Talha
Level 5 , Lahore, Pakistan
20 August 2019, 11:42
a += a; is the same as a = a+a; it'll ad the value on left to the value on right
Jimmy Phan
Level 7 , Atlanta, United States
18 October 2019, 16:30
A bit confused on the operators as well. I thought my code was way off due to a little += and = x + x differences
Daniel
Level 9 , Vienna, Austria
4 May 2020, 00:50
You add the value from the right to the value of the left. The question is who a from the left is, not who a from the right is. So lefta is lefta + righta NOT righta is lefta + righta. It that would be the case then you would talk about who righta is. Say you have valueOfA and valueOfB. valueOfA is valueOfA + valueOfB or valueOfA += valueOfB. You transfer the value from the right into the value of the left. I hope that makes sense.
Cinthya Cabanzo
Level 22 , Bogota, Colombia
24 April 2019, 20:15
Take a look a this lecture https://codegym.cc/quests/lectures/questsyntax.level04.lecture01