From f064bf0067b7b3dbadb47683cd1e9f11d4e03676 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sat, 16 Aug 2025 19:17:04 +0200 Subject: [PATCH] Update 31-earths-moon.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hey! 👋 While working on the exercise about calculating a person's weight on the Moon, I found a little mismatch: - The statement says the method should **print a message** with the result. - But the method is declared as `double`, which suggests it should **return a value** instead. 🤔 To make it consistent, I changed the method to `void` so it directly prints the result on the console 🖥️. I did also simplify the method call. Thanks for checking this out! 🙌 --- 6-methods/31-earths-moon.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/6-methods/31-earths-moon.java b/6-methods/31-earths-moon.java index 0815abb..366b877 100644 --- a/6-methods/31-earths-moon.java +++ b/6-methods/31-earths-moon.java @@ -3,21 +3,15 @@ public class HelloWorld { - public static double earthMoonWeight(String name, int weight, String unit) { + public static void earthMoonWeight(String name, int weight, String unit){ - double moonWeight = weight * (1.62 / 9.81); - return moonWeight; + double weightOnMoon = weight * (1.62 / 9.81); + String message = "Hi " + name + "! Your weight on Earth is " + weight + " and your weight on the moon would be about " + weightOnMoon + unit +". "; + System.out.println(message); } public static void main(String[] args) { - - String name = "Max"; - int earthWeight = 30; - String unit = "lbs"; - double moonWeight = earthMoonWeight(name, earthWeight, unit); - - System.out.println("Hi " + name + "! Your weight on Earth is " + earthWeight + unit + - " and your weight on the moon would be about " + moonWeight + unit + "."); + earthMoonWeight("Max",30,"lbs"); } }