import java.util.Scanner; public class InternetServiceProvider { public static void main(String [] args) { Scanner keyboard = new Scanner (System.in); String letter; double hours; double total; System.out.println("Package A: For $9.95 per month 10 hours of access are provided." + " Additional hours\nare $2.00 per hour.\n"); System.out.println("Package B: For $13.95 per month 20 hours of access are provided." + " Additional hours are\n$1.00 per hour.\n"); System.out.println("Package C: For $19.95 per month unlimited access is provided.\n"); System.out.print("Please enter a package you want(A, B, C): "); letter = keyboard.nextLine(); System.out.print("Please enter hours used: "); hours = keyboard.nextDouble(); if (letter == "A" || letter == "A") { if(hours <= 10) { total = 9.95; System.out.println("You are using " + letter + " and you used " + hours + " this month. Your total charge will be $" + total + "."); } else { total = 9.95 + ((hours-10)*2); System.out.println("You are using " + letter + " and you used " + hours + " this month. Your total charge will be $" + total + "."); } } else if(letter == "B" || letter == "B") { if(hours <= 20) { total = 13.95; System.out.println("You are using " + letter + " and you used " + hours + " this month. Your total charge will be $" + total + "."); } else { total = 13.95 + ((hours-20)*1); System.out.println("You are using " + letter + " and you used " + hours + " this month. Your total charge will be $" + total + "."); } } else if(letter == "C" || letter == "C") { total = 19.95; System.out.println("You are using " + letter + " and you used " + hours + " this month. Your total charge will be $" + total + "."); } } }
As you can see, this problem, you have to make user to prompt internet service A, B, or C and number of hours used and print the total. When I compile, it compiles but it doesn't print the result at all. if I place println outside of brace, it tells me total is not initialized. What's wrong with my code and why wouldn't it print the result?