I just did the syntax for my program but the error I keep getting is that that java.io is not read.

import java.util.*;



public class EnergyConverter 
{

	//main(): application entry point
	public static void main(String[] args) 
	{
		
		//get option and numbers
		int Option = 0;
		double Amount = 0;
		double Total = 0;
		
		//set input stream
		Scanner in = new Scanner(System.in);
		Option = in.nextInt();
	
		// Menu title
		System.out.println("Enegry Conversion Program");
		System.out.println("");


		
		//Menu Prompt
		while (Option != 4)
		{

		 System.out.println("Conversion Type:");
		 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");
		 System.out.println("");
		 
		 System.out.print("Please enter your selection: ");

			 if (Option == 1)
			 {
				 System.out.print("What is the amount of BTUs to be converted ");
				 Total = (Amount * 1056);
				 System.out.println("Conversion: " + Total + " joules\n");
			 }
			 else if (Option == 2)
			 {
				 System.out.print("What is the amount of Calories to  be converted ");
				 Total = (Amount * 4.184);
				 System.out.println("Conversion: " + Total + " joules\n");
			 }
			 else if (Option == 3)
			 {
				 System.out.print("What is the amount of Joules to be converted ");
				 Total = (Amount * 1);
				 System.out.println("Conversion: " + Total + " joules\n");
			 }
			 else if (Option == 4)
			 {
				 System.out.print("Thank you for using Energy Conversion ");	 
			 }
			 else
			 {
				 System.out.println(" You have entered an invalid selection, please try again");
				 System.out.print("Please enter your selection: ");
			 }

		 
		 
	}
		
	}
}

I don't know exactly what I did wrong and I have been staring at it for the last 30 mins.

What does the line: Option = in.nextInt(); do?

My guess is that it accepts user input right?

At what point do you want to accept user input? Before you tell the user what their options are? Before you tell them what the name of the program is? My guess is you want to get a users input after your explain what there different options are.

Regards,

Nate

You're also not setting your Amount variable with any user input...

You'll most likely need to add a few: Amount = in.nextInt(); lines.

Regards,

Nate

Ok I see my error there. Thanks. But it still doesn't help me with this problem or compile error. :(

It is stuck in a loop and it won't stop running.

You're also not setting your Amount variable with any user input...

You'll most likely need to add a few: Amount = in.nextInt(); lines.

Regards,

Nate

Right when I read that, I just saw the problem...thanks again :o

This article has been dead for over six months. Start a new discussion instead.