This is the code, in this code when i try to compile it tell me that price might not have been initialized. I went through the code and cant find whats wrong . can someone tell me why the price variable might not be initialized and also tell me how to fix it.
// BillyGoat.java - This program looks up and prints the names and prices of fast-
food items.
// Input: Interactive.
// Output: Name and price of fast-food item or error message if fast-food item is
not found.
import javax.swing.*;
public class BillyGoat
{
public static void main(String args[]) throws Exception
{
double price;
int custNum; // Customer number.
String custString; // String version of customer number.
String itemName; // Name of item ordered.
final int NUM_ITEMS = 3; // Named constant
// Initialized array of food items.
String foodItems[] = {"Cheeseburger", "Pepsi", "Chips"};
// Initialized array of food prices.
double foodPrices[] = {2.49, 1.00, .59};
boolean foundIt = false; // Flag variable.
int sub; // Loop control variable.
String QUIT="finish";
// Get user input.
custString = JOptionPane.showInputDialog("Enter customer number: ");
custNum = Integer.parseInt(custString);
itemName = JOptionPane.showInputDialog("Enter item name: ");
while(itemName.compareTo("finish") !=0)
{
sub=0;
foundIt=false;
while(sub<3)
{
if(itemName==foodItems[sub])
{
foundIt = true;
price=foodPrices[sub];
}
x++;
}
if(foundIt==true)
{
System.out.println("the amount of:" + itemName + "is" + price);
}
else{
System.out.println(" we do not carry this please choose another
selection");
}
custString = JOptionPane.showInputDialog("Enter customer number: ");
custNum = Integer.parseInt(custString);
itemName = JOptionPane.showInputDialog("Enter item name or finish to
quit ");
}
System.exit(0);
} // End of main() method.
} // End of BillyGoat class.