Computer Science Canada

dr java....might not have been initialized error What am i doing wrong?

Author:  you2weak [ Sat Apr 09, 2011 5:40 pm ]
Post subject:  dr java....might not have been initialized error What am i doing wrong?

import java.util.Scanner;
public class practice
{ //Declares the class

public static void IntroInstructions () //method is defined
{
Scanner input = new Scanner (System.in); //defines the Scanner (which was imported at the beginning of the program)

String introContinue; //declaration of the variable that stores the user's inputted value to continue to the next section of the program

System.out.println ("Egg-cellent Choice Restaurant Welcome you Smile Here you can find wonderful breakfast choices which will make your morning absolutely Egg-cellent!");
System.out.println ("So, go ahead and choose your meal by following the instructions!"); //general output
System.out.println ("");
System.out.println ("Press any key to continue.");
introContinue = input.next(); //waits for user input to continue to the next section
input.close(); //closes the input stream used previously

}
public static void main (String[] args) { //Main method
int purchasePrice; //declares the integer



Scanner input = new Scanner(System.in);
System.out.println(" Menu");
System.out.println(" 1. Great Eggs-pectations");
System.out.println(" 2. Skillets and Scrambles");
System.out.println(" 3. Omelettes");
System.out.println(" 4. Eggs Ole");
System.out.println(" 5. Pancakes, Waffles & French Toast");




System.out.println("Enter the dish you would like to choose:");//What should be inputted in the box
purchasePrice = input.nextInt();
input.close();
input.close();


}
public static void gretEggspectations () //method is defined
{
Scanner input = new Scanner (System.in); //defines the Scanner (which was imported at the beginning of the program)

int greatEggspectations;
int choicegroupOne;
double greatEggspectationsSubtotal;
double dishTotalgroupone = 0;



System.out.println(" Great Eggs-pectations");
System.out.println(" 1. Eggs Plus.........................$5.89");
System.out.println(" 2. Turkey Sausage and Eggs...........$7.49");
System.out.println(" 3. Eggs Petite.......................$4.89");
System.out.println(" 4. Breakfast Croissant...............$7.99");
System.out.println(" 5. Steak and Eggs....................$9.99");
System.out.println(" 6. Corned Beef Hash..................$8.59");
System.out.println(" 7. Biscuit & Gravy...................$6.67");
System.out.println(" 8. Deluxe Breakfast Sandwich.........$8.59");
choicegroupOne = input.nextInt();

if (choicegroupOne == 1.) { //if the inputted value for the variable is equal to 1 then...
dishTotalgroupone = 5.89; //set value of individualCerealTotal variable to item's price, in this case 2.99
System.out.println ("You selected Eggs Plus"); //output the chosen selection of cereal
System.out.println ("The price on this item is $" + dishTotalgroupone); //outputs the price of the individual item; pre set by user's input
input.close();
}


}//Closing bracket
}//Closing bracket

Author:  Tony [ Sat Apr 09, 2011 5:58 pm ]
Post subject:  RE:dr java....might not have been initialized error What am i doing wrong?

The compiler doesn't know if that certain variable is always guaranteed to hold some value.

Author:  you2weak [ Sat Apr 09, 2011 6:06 pm ]
Post subject:  RE:dr java....might not have been initialized error What am i doing wrong?

so how do i fix that?

Author:  Tony [ Sat Apr 09, 2011 6:25 pm ]
Post subject:  RE:dr java....might not have been initialized error What am i doing wrong?

Initialize your variables before use.


: