So, every time I compile this, I get a single error on line 71 or the last part of the second If-Else statement. When I compile it, I get an error saying that my variable "bd" was not initialized.
The line in question is
else if (a == 3)
{
discount = bd;
}
I attached a zip with my java file in it, if that helps in solving the problem.
Thanks in advance!
import java.util.Scanner; //for the ability to get input from //the keyboard import java.text.DecimalFormat; public class WebsterAaronProject2 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); DecimalFormat df = new DecimalFormat("00.0"); double dp; double sr = 5.00; double at = 0; double st = 0; double bd; double discount = 0; double total = 0; double beforeDiscount = 0; int a; System.out.println("******* WELCOME TO THE TICKET PRICE CALCULATOR ******"); System.out.println(" created by Aaron Webster"); freezeScreen(); clearScreen(); System.out.print("How many adult tickets do you wish to purchase (ages 18-64): "); at = keyboard.nextDouble(); System.out.print("How many student/senior tickets do you wish to purchase (0-17 or 65+): "); st = keyboard.nextDouble(); clearScreen(); System.out.print("Please make a selection from the menu options below for additional savings.\n\n"); System.out.print(" Savings Menu \n ----------------------\n"); System.out.println("1. Free Shipping"); System.out.println("2. 10.0% Discount"); System.out.println("3. Apply whichever discount will save me the most money \n"); System.out.print("Enter your selection : "); a = keyboard.nextInt(); dp = (at * 10 + st * 5) * .10; if (sr <= dp) { bd = dp; } else if (dp <= sr) { bd = sr; } if (a == 1) { discount = sr; } else if (a == 2) { discount = dp; } else if (a == 3) { discount = bd; } beforeDiscount = (at * 10) + (st * 5); total = (beforeDiscount - discount) + sr; clearScreen(); System.out.println("Purchase price $ " + beforeDiscount); System.out.println("Discount applied $-" + discount); System.out.println("Shipping $ " + sr); System.out.println("--------------------------------------------"); System.out.print("Total Due $ " + total + "\n\n\n"); System.out.print("****** Thank you for using THE TICKET PRICE CALCULATOR *******"); } //end main public static void clearScreen() { System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); }//end clearScreen public static void freezeScreen(String msg) { Scanner keyboard = new Scanner(System.in); System.out.print(msg); keyboard.nextLine(); }//end freezeScreen public static void freezeScreen() { Scanner keyboard = new Scanner(System.in); System.out.print(" -- Press Enter to Continue --"); keyboard.nextLine(); } }