Hello All. Im doing a very simple unit converter for my Comp Sci class and I need a little help with a bug. This is the code that I have so far:
|
Code:
|
import java.util.Scanner;
public class UnitConverter {
public static void main(String[] args)
{
int initialAmount;
double convertedAmount;
System.out.println("Welcome to Ryan's Unit Converter");
System.out.println();
System.out.println("Which unit would you like to convert from:");
System.out.println("centimeter feet inch kilometer league meter microinch mile millimeter yard?");
Scanner kboard = new Scanner(System.in);
String fromUnit = kboard.nextLine();
System.out.println();
System.out.println("Which unit would you like to convert to?");
System.out.println("centimeter feet inch kilometer league meter microinch mile millimeter yard?");
String toUnit = kboard.nextLine();
System.out.println();
System.out.println("You are converting from " + fromUnit + " to " + toUnit + "?");
System.out.println("How many " + fromUnit + " would you like to convert to " + toUnit + "?");
initialAmount = kboard.nextInt();
if(fromUnit.equals("centimeter") && toUnit.equals("feet"))
convertedAmount = initialAmount * 0.033;
System.out.println(convertedAmount);
} |
It's only halfway done, so Im just testing out converting centimeters to feet for now. However, if I try to run, it gives me the error "variable convertedAmount might not have been initialized
System.out.println(convertedAmount);"
I don't understand because I did initialize convertedAmount at the top. I just think that there's an error having to do with doubles and ints.
Sorry if I seem like such a java newb but Im just trying to get on my feet. Any help?
Thanks again.