package moonweight import javautilScanner public class MoonW

package moonweight;
import java.util.Scanner;

public class MoonWeight {

/*
Program to calculate weight on earth
to weight on moon.
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
  
double earthWeight; //weight on earth
double moonWeight; //weight on moon

System.out.print(\"Enter your weight in pounds: \");
earthWeight = input.nextDouble();
  
if (earthWeight <= 0.0)
{
System.out.print(\"Please enter a positive number. \");
earthWeight = input.nextDouble();
}
moonWeight = earthWeight * 0.17;
System.out.println(earthWeight + \" earth pounds is equal to \" +
moonWeight + \" moon pounds.\");
}
}

Tax rate Calculator:

package taxcalculator;
import java.util.*;

public class TaxCalculator {

public static void main(String[] args) {
System.out.print(\"Enter the Single Filers Income: \");
Scanner input = new Scanner(System.in);
double income = input.nextDouble();
double tax;
  
if(income <= 6000)
tax = income * .1;
else if(income <= 27950)
tax = income * .15;
else if(income <= 67700)
tax = income * .27;
else if(income <= 141250)
tax = income * .3;
else if(income <= 307050)
tax = income * .35;
else
tax = income * .386;
System.out.printf(\"Income tax for a single person making $%.2f income is $%.2f\ \", income, tax);
}
  
}

Grade range:

package gradeupdate;
import java.util.Scanner;

public class GradeUpdate {

public static void main(String[] args) {
int grade;
System.out.print(\"Enter grade between 0 and 100: \");
Scanner input = new Scanner(System.in);
grade = input.nextInt();
  
if (grade>=90 & grade<=100) {
System.out.println(\"You got an A. Excellent!\");
} else if (grade>=80 & grade<90) {
System.out.println(\"You got a B. Good!\");
} else if (grade>=70 & grade<80) {
System.out.println(\"You got a C. OK\");
} else if (grade>=60 & grade<70) {
System.out.println(\"You got a D. Try harder\");
} else {
System.out.println(\"You got an F. Try harder\");
}
}
}

Use a Do-While loop and Switch Case to create menu of programs you have already created. The menu should be able to loop and execute programs until user wants selects to quit. e a *Main Menu: * 2 Enter # to run program or Quit 1) Moon Weight Calculator * 1) Moon Weight Calculator 2 *2) Tax Rate Calculator *3) Grade Range * 4) Quit a3 You Selected Option 1: Enter Earth Weight: 120 Moon Weight: 100lbs

Solution

I kept you code in this program and done some modifications.Thank You

Menu.java

import java.util.Scanner;

public class Menu {

   public static void main(String[] args) {
       //Declaring variable
       int option;
      
       //Scanner class Object is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //This do-while loop continues to execute until user select option \'4\'
       do
       {
       //Displaying the menu  
       System.out.println(\"\ *****************************\");
       System.out.println(\"* Main Menu:\");
       System.out.println(\"* 1. Moon Weight Calculator \");
       System.out.println(\"* 2. Tax rate Calculator \");
       System.out.println(\"* 3. Grade Range \");
       System.out.println(\"* 4. Quit \");
       System.out.println(\"*****************************\");
      
       //Getting the user selected option
       System.out.print(\"You Selected Option :\");
       option=sc.nextInt();
      
       /* Based on the user selected option the
       * corresponding case will get executed
       */
       switch(option)
       {
       case 1:{
           //Declaring variables
           double earthWeight; //weight on earth
           double moonWeight; //weight on moon

                  
           //This loop continue to execute until user entered positive number
           while(true)
           {
               //getting the weight of the person on the earth
               System.out.print(\"\ Enter your weight in pounds: \");
               earthWeight = sc.nextDouble();
               if(earthWeight <= 0.0)
               {
                   //Displaying error message
                   System.out.print(\":: Please enter a positive number :: \");
                   continue;
               }
               else
                   break;
           }
          
           //Calculating the weight on the moon
           moonWeight = earthWeight * 0.17;
          
           //Displaying the weight on the moon
           System.out.printf(\"%.2f earth pounds is equal to %.2f moon pounds.\",earthWeight,moonWeight);
           continue;
          
       }
       case 2:{
          
           double tax;
          
           //Getting the taxable amount entered by the user.
           System.out.print(\"Enter the Single Filers Income: \");
           double income = sc.nextDouble();
          
           /* Based on the taxable amount the corresponding
           * block of code will get executed.
           */
           if(income <= 6000)
           tax = income * .1;
           else if(income <= 27950)
           tax = income * .15;
           else if(income <= 67700)
           tax = income * .27;
           else if(income <= 141250)
           tax = income * .3;
           else if(income <= 307050)
           tax = income * .35;
           else
           tax = income * .386;
          
           //Displaying the tax
           System.out.printf(\"Income tax for a single person making $%.2f income is $%.2f\ \", income, tax);
           continue;
       }
       case 3:{
           //Declaring variables
           int grade;
          
           //Getting the Grade entered by the user.
           System.out.print(\"Enter grade between 0 and 100: \");
           grade = sc.nextInt();
             
           //Based on the grade value the corresponding block of code will get executed.
           if (grade>=90 & grade<=100) {
           System.out.println(\"You got an A. Excellent!\");
           } else if (grade>=80 & grade<90) {
           System.out.println(\"You got a B. Good!\");
           } else if (grade>=70 & grade<80) {
           System.out.println(\"You got a C. OK\");
           } else if (grade>=60 & grade<70) {
           System.out.println(\"You got a D. Try harder\");
           } else {
           System.out.println(\"You got an F. Try harder\");
           }
           continue;
       }
       case 4:{
           break;
       }
          
       }
       }while(option!=4);

   }

}

_______________________________________

Output:


*****************************
* Main Menu:
* 1. Moon Weight Calculator
* 2. Tax rate Calculator
* 3. Grade Range
* 4. Quit
*****************************
You Selected Option :1

Enter your weight in pounds: -150
:: Please enter a positive number ::
Enter your weight in pounds: -100
:: Please enter a positive number ::
Enter your weight in pounds: 160
160.00 earth pounds is equal to 27.20 moon pounds.
*****************************
* Main Menu:
* 1. Moon Weight Calculator
* 2. Tax rate Calculator
* 3. Grade Range
* 4. Quit
*****************************
You Selected Option :2
Enter the Single Filers Income: 60000
Income tax for a single person making $60000.00 income is $16200.00

*****************************
* Main Menu:
* 1. Moon Weight Calculator
* 2. Tax rate Calculator
* 3. Grade Range
* 4. Quit
*****************************
You Selected Option :3
Enter grade between 0 and 100: 91
You got an A. Excellent!

*****************************
* Main Menu:
* 1. Moon Weight Calculator
* 2. Tax rate Calculator
* 3. Grade Range
* 4. Quit
*****************************
You Selected Option :4

_______________Thank You

package moonweight; import java.util.Scanner; public class MoonWeight { /* Program to calculate weight on earth to weight on moon. */ public static void main(St
package moonweight; import java.util.Scanner; public class MoonWeight { /* Program to calculate weight on earth to weight on moon. */ public static void main(St
package moonweight; import java.util.Scanner; public class MoonWeight { /* Program to calculate weight on earth to weight on moon. */ public static void main(St
package moonweight; import java.util.Scanner; public class MoonWeight { /* Program to calculate weight on earth to weight on moon. */ public static void main(St
package moonweight; import java.util.Scanner; public class MoonWeight { /* Program to calculate weight on earth to weight on moon. */ public static void main(St

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site