I am attending college for computer programming and came across a practice question where I am keep getting a compiler error: local varialbe movieFee, snackFee and couponeFee is not initialized at line 85.
I am new to this and I feel like I have done everything right. Could someone kindly help me out?
Thank you! Joseph
Question is: Calculate the cost of going to the movie theatre. Pick the appropriate age range – child, adult, or senior; choose a snack bar combo – none, popcorn and pop, chocolate bar and pop, or popcorn and candy and pop; indicate if the patron has a coupon which gives him $2 off the movie fee.
Patron Age Ranges       Movie Fee       Snack Bar Options       Fee
child ( < 12)       $5.50       A - popcorn and pop     $7.90
adult (12 - 65)     $8.50       B - chocolate bar and pop       $6.30
senior ( > 65)      $6.00       C - popcorn and candy and pop       $8.90
My code is:
import java.util.Scanner; public class MovieFee {
public static void main(String[] args)
{
    //scanner class
    Scanner input=new Scanner(System.in);
    //display the age options and prompt the user to enter one
    System.out.println("Child (<12)");
    System.out.println("Adult (12-65)");
    System.out.println("Senior (>65)");
    System.out.print("Choose your age category: ");
    String age=input.nextLine();
    //display the snak bar options and prompt the user to enter one
    System.out.println("\n\nA - popcorn and pop");
    System.out.println("B - chocolate bar and pop");
    System.out.println("C - popcorn and candy and pop");
    System.out.print("What is your snack bar option(enter a letter): ");
    String snackOption=input.nextLine();
    //calculate the movie fee
    //declare fee variables
    double movieFee, snackFee;
    if(age=="child"||age=="Child")
    {
        movieFee=5.50;
    }
    else if(age=="adult"||age=="Adult")
    {
        movieFee=8.50;
    }
    else if(age=="senior"||age=="Senior")
    {
        movieFee=6.00;
    }
    else
    {
        System.out.println("\nYou did not enter a correct age group.");
        System.out.println("Please try again using one of: child, adult, senior");
    }
    //calculate the snack fee
    if(snackOption=="A"||snackOption=="a")
    {
        snackFee=7.90;
    }
    else if(snackOption=="B"||snackOption=="b")
    {
        snackFee=6.30;
    }
    else if(snackOption=="C"||snackOption=="c")
    {
        snackFee=8.90;
    }
    else
    {
        System.out.println("\nYou did not enter a correct option");
        System.out.println("Please try again using either A, B or C");
    }
    //ask the user if he/she has a coupon
    double couponFee;
    System.out.print("\nDo you have a coupon? Type yes or no: ");
    String coupon=input.nextLine();
    if(coupon=="yes")
    {
        couponFee=2.0;
    }
    else if(coupon=="no")
    {
        couponFee=0;
    }
    //calculate the total fee and total fee
    double result=movieFee+snackFee+couponFee;   //**GETTING ERROR HERE
    System.out.println("Final price is "+result);
}
//end main
}
//end class
 
     
     
     
     
     
     
     
    