import java.util.Scanner; //import scanner statement public class InternetServiceProvider { public static void main(String [] args) { Scanner keyboard = new Scanner (System.in); //scanner object String service; //service package choice double hours; //hours used double total; //total amount due System.out.println("Package A: For $9.95 per month 10 hours of access are provided." + " Additional hours\nare $2.00 per hour.\n"); //print service package A rate and price 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"); //print service package B rate and price System.out.println("Package C: For $19.95 per month unlimited access is provided.\n"); //print service package C rate and price System.out.print("Please enter a package you want(A, B, C): "); //prompt service package choice service = keyboard.nextLine(); //accept service package input System.out.print("Please enter hours used: "); //prompt hours used hours = keyboard.nextDouble(); //accept hours used input if (service.equals("A")) //if statement for service A package { if(hours <= 10) { total = 9.95; //total System.out.println("You are using " + service + " and you used " + hours + " hours this month. Your total charge will be $" + total + "."); //print the result for 10 hours or less used } else { total = 9.95 + ((hours-10)*2); //calculate total System.out.println("You are using " + service + " and you used " + hours + " hours this month. Your total charge will be $" + total + "."); //pritn the result for 10+ hours used } } else if(service.equals("B")) //if statement for service B package { if(hours <= 20) { total = 13.95; //total System.out.println("You are using " + service + " and you used " + hours + " hours this month. Your total charge will be $" + total + "."); //print the result for 20 hours or less used } else { total = 13.95 + ((hours-20)*1); //calculate total System.out.println("You are using " + service + " and you used " + hours + " hours this month. Your total charge will be $" + total + "."); //print the result for 20+ hours used } } else if(service.equals("C")) //if statement for service C package { total = 19.95; //total System.out.println("You are using " + service + " and you used " + hours + " hours this month. Your total charge will be $" + total + "."); //print the result } } }
ok. This is my initial code that suppose to prompt user to choose one of 3 internet service plans which are plan A, B, C and then how many hours user used it. It then prints out the total cost.
Now, I am having problem. How do you alter this code to compare result from A to B and A to C. for example, user would get $29.95 if he choose plan A and use for 20 hours. But if he choose plan B and use for 20 hours, he would get $13.95. So how do I make this to compare those two prices and print out the difference? I was thinking about compareTo method but I only know how to do it with basic strings like comparing names. Can anyone help me out on this?