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\");
}
}
}

Solution

Hi,

I have written a new class that holds do-while loop and from that calling yor classes. Please find the below code.

Please run this file. No other changes required.

MenuChoice.java

import java.util.Scanner;


public class MenuChoice {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
          
       do{
           System.out.println(\"***********************\");
           System.out.println(\"Main Menu:\");
           System.out.println(\"Ebter # to run program or Quit\");
           System.out.println(\"1) Moon Weight Calculator\ 2) Tax Rate Calculator\ 3) Grade Range\ 4) Quit\");
           int choice = scan.nextInt();
          
           switch(choice){
           case 1: System.out.println(\"You Selected Option \"+choice+\": \");MoonWeight.main(null);break;
           case 2: System.out.println(\"You Selected Option \"+choice+\": \");TaxCalculator.main(null); break;
           case 3: System.out.println(\"You Selected Option \"+choice+\": \");GradeUpdate.main(null);break;
           case 4: System.exit(0);break;
           }
          
       }while(true);

   }

}

Output:

***********************
Main Menu:
Ebter # to run program or Quit
1) Moon Weight Calculator
2) Tax Rate Calculator
3) Grade Range
4) Quit
1
You Selected Option 1:
Enter your weight in pounds: 120
120.0 earth pounds is equal to 20.400000000000002 moon pounds.
***********************
Main Menu:
Ebter # to run program or Quit
1) Moon Weight Calculator
2) Tax Rate Calculator
3) Grade Range
4) Quit
2
You Selected Option 2:
Enter the Single Filers Income: 1000
Income tax for a single person making $1000.00 income is $100.00
***********************
Main Menu:
Ebter # to run program or Quit
1) Moon Weight Calculator
2) Tax Rate Calculator
3) Grade Range
4) Quit
3
You Selected Option 3:
Enter grade between 0 and 100: 70
You got a C. OK
***********************
Main Menu:
Ebter # to run program or Quit
1) Moon Weight Calculator
2) Tax Rate Calculator
3) Grade Range
4) Quit
4
You Selected Option 4:

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