1. the program needs to convert btu to jules
2. Convert calories to joules
3. Convert joules to joules
4 exit the program.
if the user type anything other than 1-4 the program should print a error message.
here is my code.
2. Convert calories to joules
3. Convert joules to joules
4 exit the program.
if the user type anything other than 1-4 the program should print a error message.
here is my code.
Code:
import java.util.Scanner; public class joules { public static void main (String [] args) { final double BTUs = 1056; final double calories = 4.184; final double joule = 1; Scanner stdin = new Scanner(System.in); System.out.println ("1. Convert BTUs to joules"); System.out.println ("2. Convert Calories to joules"); System.out.println ("3. Convert joules to joules"); System.out.println ("4. Exit program"); int choice = stdin.nextInt(); while (choice != 4) if (choice < 1 || choice > 3) //converting to joules using constants if (choice = 1) { double amount = stdin.nextDouble(); double joules = amount * BTUs; System.out.println (amount + " BTUs is " + joules "joules"); } if (choice = 1) {double amount = stdin.nextDouble(); double joules = amount * calories; System.out.println (amount + " Calories is " + joules + "joules"); } if (choice = 1) { double amount = stdin.nextDouble(); double joules = amount * joule; System.out.println (amount + " joules is " + joules + "joules"); } //statement for wrong entries else { System.out.println ("That is not a valid entry. Try again"); }
Comment