Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Allow the user to input their weight for the earth weight to moon weight convers

ID: 3579745 • Letter: A

Question

Allow the user to input their weight for the earth weight to moon weight conversion problem. Add an if statement that prompts the user if she inputs 0 or a negative number for her earth weight. Add single and multi-line comments to your code so that people looking into your program understand the things you are attempting to do with each section of code. Use Object Orientated Design (OOP), Use Constructors, Parameters, and arguments as needed. Create 1 method that sets the value for weight Write a program that has 4 methods that will return the weight conversions for the following. method will convert Weight on Earth's Moon. method will convert Weight on Mars method will convert Weight on Venus method will convert Weight on Mercury Create a menu that gives the user choice and con Show number of seconds, converted to hours, converted to minutes, and remaining seconds.

Explanation / Answer

CODE:

import java.util.Scanner;

public class Weight {
public static void main(String args[]){
   Scanner in=new Scanner(System.in);
  
   int choice;
   float weight;
   do{
       System.out.print("Menu for conversion of your weights ");
       System.out.print("1>To calculate your weight on Earth's Moon ");
       System.out.print("2>To calculate your weight on Mars ");
       System.out.print("3>To calculate your weight on Venus ");
       System.out.print("4>To calculate your weight on Mercury ");
       System.out.print("5>Exit ");
       System.out.print("Enter your choice ");
       choice=in.nextInt();
       switch(choice){
       case 1:
System.out.print(" Enter your weight on earth ");
weight=in.nextInt();
System.out.print("Your weight on Earths moon is "+ Weight.moonWeight(weight)+" ");
break;
       case 2:
System.out.print(" Enter your weight on earth ");
weight=in.nextInt();
System.out.print("Your weight on Mars is "+ Weight.marsWeight(weight)+" ");
break;
       case 3:
System.out.print(" Enter your weight on earth ");
weight=in.nextInt();
System.out.print("Your weight on Venus is "+ Weight.venusWeight(weight)+" ");
break;
       case 4:
System.out.print(" Enter your weight on earth ");
weight=in.nextInt();
System.out.print("Your weight on Mercury is "+ Weight.mercuryWeight(weight)+" ");
break;
  
       case 5:
           return;
  
       }
   }while(choice!=5);
  
  
}
public static float moonWeight(float weight){
   float mweight=weight/6;
   return mweight;
}
public static float marsWeight(float weight){
   float mweight=(float) ((weight/9.81)*3.711);
   return mweight;
}
public static float venusWeight(float weight){
   float mweight=(float) ((weight/9.81)*8.87);
   return mweight;
}
public static float mercuryWeight(float weight){
   float mweight=(float) ((weight/9.81)*3.7);
   return mweight;
}
}

SAMPLE OUTPUT:

Menu for conversion of your weights
1>To calculate your weight on Earth's Moon
2>To calculate your weight on Mars
3>To calculate your weight on Venus
4>To calculate your weight on Mercury
5>Exit
Enter your choice
1

Enter your weight on earth
90
Your weight on Earths moon is 15.0


Menu for conversion of your weights
1>To calculate your weight on Earth's Moon
2>To calculate your weight on Mars
3>To calculate your weight on Venus
4>To calculate your weight on Mercury
5>Exit
Enter your choice
2

Enter your weight on earth
90
Your weight on Mars is 34.04587


Menu for conversion of your weights
1>To calculate your weight on Earth's Moon
2>To calculate your weight on Mars
3>To calculate your weight on Venus
4>To calculate your weight on Mercury
5>Exit
Enter your choice
3

Enter your weight on earth
90
Your weight on Venus is 81.376144


Menu for conversion of your weights
1>To calculate your weight on Earth's Moon
2>To calculate your weight on Mars
3>To calculate your weight on Venus
4>To calculate your weight on Mercury
5>Exit
Enter your choice
4

Enter your weight on earth
90
Your weight on Mercury is 33.944954


Menu for conversion of your weights
1>To calculate your weight on Earth's Moon
2>To calculate your weight on Mars
3>To calculate your weight on Venus
4>To calculate your weight on Mercury
5>Exit
Enter your choice

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote