Group Assignment c= Math.pow(a,b) //variables must be of type double Everything
ID: 3746159 • Letter: G
Question
Group Assignment c= Math.pow(a,b) //variables must be of type double Everything should reside in a single ava file called Menu.java You have the freedom to put everything in one class. Also everything can be in the main function. Upon selecting option 2, you should call method gravity that does the following: The moon's gravity is about 17% of Earth's write a program that accepts your weight here on earth and then calculates and displays your weight on the moon. Display the menu options 1) Hypotenuse 2) Gravity 3) Quit Validation: the input should be validated using a while loop. The input should be between 100 and 300 (inclusive) The program should run continuously until the user selects option 3. (Validate input using do/while) What to turn in: Upon selecting option 1, you should call method Hypotenuse that does the follow- Menu.java file (NOTE: I do not want any more print screens. Just the java file) ing: Ask the user to input the length for the shortest sides of a right triangle. Calcu late and display the length of the longest side (Hypotenuse) Formula: If (a) and (b) represent the shortest sides and (c) represents the Validation:The inputs must be validated using do/while loops. The inputs Hint: Use the pow and sqrt methods in the Math class longest side then the formula is cVab Example of validation: public static void main(String[] args) Scanner reader-new Scanner(System.inl); int score; boolean valid; should be between 2 and 20 (inclusive) Square root and pow examples double a-9,b,c; b-Math.sqrt(a); dol //variables must be declared of type valid true; System.out.println("What is your score 0 and 100:" doubleExplanation / Answer
import java.util.Scanner;
public class Menu {
public static void main(String args[]) {
Scanner in =new Scanner (System.in);
int choice;
do {
do{ System.out.print("Enter choice : ");
choice =in.nextInt();
}while(choice<1 ||choice >3);
switch(choice) {
case 1:{
hypotenuse();
break;
}
case 2:{
gravity();
break;
}
}
}while(choice !=3);
in.close();
}
public static void hypotenuse() {
double a,b;
Scanner input = new Scanner (System.in);
do {
System.out.println("Enter sides (2 - 20) : ");
System.out.print("Enter a = ");
a=input.nextDouble();
System.out.print("Enter b = ");
b=input.nextDouble();
}while((a<2 ||a >20)||(b<2 ||b>20));
System.out.printf("hypotenuse of trangle : %.2f ",Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)));
input.close();
}
public static void gravity() {
double weight;
Scanner input = new Scanner (System.in);
do {
System.out.print("Enter weight (100 - 300) : ");
weight = input.nextDouble();
}while(weight<100 ||weight >300);
System.out.println("weight on moon : "+weight*0.17);
input.close();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.