Even to the moon!

  • 7
  • Locked
Programmers often move from place to place, but only if they want to. That's why they love converters so much. Well, maybe that's not why. Still, we will practice writing them. Now imagine that you have to work at a particular location: the Moon. Let's implement a method that converts your Earth weight to your lunar weight.
You can't complete this task, because you're not signed in.
Comments (14)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Jeff Kenney
Level 3 , United States
14 December 2021, 06:23
Okay, so I'm really getting the hang of the conversion program formula: Basically, all you need for ANY simple conversion program (lbs to kg...in to cm...feet to meters...) IS: A) One line of code to define a conversion formula (you only need one) Example: double VariableOne = 1/2*VariableTwo+37; B) State which variable to calculate for with the "return"
Víctor Alfonso Martínez Gómez
Level 3 , Manizales, Colombia
10 August 2021, 21:40
Level 3 , Austin, United States
25 July 2021, 03:42
Am I the only one that's pretty far lost at this point?
16 December 2020, 09:32
When I googled the formula it gives a different value. Why do we calculate by the hint and not the actual formula for a precise result?
Level 41
18 December 2020, 07:18
Yes, you are right. Wiki says : "The acceleration due to gravity on the surface of the Moon is about 1.625 m/s2, about 16.6% that on Earth's surface or 0.166 ɡ." We just rounded it up)
Bosch Testing Team
Level 12 , Karlsruhe, Germany
14 November 2020, 18:44
Hi guys, can some one help me understand why code on the left returns correct decimal value but code on the right does not ? Tnx
Yusuf el Turki
Level 5 , Rhein, Germany
18 May 2021, 13:47
Same problem.0.17 and *17 / 100 is same thing but the result is different. I also dont understand.
10 August 2021, 07:48
I doubt this person is gonna read this 2 years later but I'll answer it anyway for people that may have the same issue now. even if you use the "double" command, if You dont input any decimals on any number of the calculation, java is gonna treat it like and "int" anyway. So if you input *17.0/100 instead for example, it would work properly.
Raunak Adhikari
Level 12 , India
15 August 2020, 10:23
take double lunar weight and gravity....assign the value of gravity to 0.17..then lunarweight = gravity multiplied by earth weight.....then return the lunar weight........
Level 20 , Budapest, Hungary
14 April 2019, 19:23
So you already taught us how to use static variables, but if I try to use it in the task it thorws me an error, I think it would be better than magic numbers. I've tried to use this: public static final double LUNAR_GRAVITY = 0.17;
Level 3 , United States
20 September 2019, 14:32
the static is already provided in the exercise
Level 20 , Budapest, Hungary
22 September 2019, 11:55
What do you mean? I can not see any static variable declared in the source. I just mentioned that it would be more convenient to use a final declaration.
Bryce Lindley
Level 9 , Olympia, United States
19 January 2019, 22:53
Please excuse my dear aunt sally
Level 4 , Hyderabad, India
29 December 2018, 06:24
oh god!i felt some difficulty but finally did it.