Im doing a program that will allow the users to enter the data input units (BTU, calorie, or joule) and give an output that is the energy in joules.
But if the user types anything other than options 1, 2, 3, or 4, the program should print an error message, and prompt the user for more input.
here is my codes so far:
My problem is i cant get the code work whenver the user enter more than option 4 it's not going back to the loop so the user can enter again, the screen just exits out..
import java.util.*;
public class project02{
//main():application entry point
public static void main(
String[] args) {
//define constants
final double Bjoules = 1056; //equivalent of 1 joules to BTU
final double Cjoules = 4184; //equivalent of 1 joules to calories
final double Jjoules = 1; //equivalent of 1 joules to joules
//set up input stream
Scanner stdin = new Scanner(System.in);
//display user input
System.out.print("Enter a number between 1 to 4 and hit enter: : ");
double inputNumber = stdin.nextDouble();
while (inputNumber <=4) {
inoutNumber = stdin.nextDouble();
}
if(inputNumber == 1) {
System.out.print("Enter the Number of BTU: ");
double BTU = stdin.nextDouble();
BTU= BTU * Bjoules;
System.out.println("BTU" + " = " + BTU + " no. of joules" );
}
else if (inputNumber == 2) {
System.out.print("Enter the Number of calories: ");
double Calories = stdin.nextDouble();
Calories = Calories * Cjoules;
System.out.println("Calories "+ " = " + Calories + " no. of joules");
}
else if (inputNumber == 3) {
System.out.print("Enter the Number of Joules: ");
double Joules = stdin.nextDouble();
Joules = Joules * Jjoules;
System.out.println("Joules" + " = " + Joules + " no. of joules");
}
else if (inputNumber == 4){
System.out.println("Exit");
}
else {
System.out.println("Error");
System.out.println("Please enter a number between 1 to 4 and hit enter: : ");
}
}
}
thanks much...