preview

Computer Program to Calculate a Customer's Monthly Cellphone Bill

Better Essays

1.*Cell Phone Data Packages A cell phone provider provides 3 different data packages: Package A: 50 MB: For $5 per month a customer gets 50 MB of data usage. Package B: 200 MB: For $15 per month a customer gets 200 MB of data usage. Package C: 1 GB: For $25 per month a customer gets 1 GB of data usage. Additional usage over the allotted amount for each plan is charged at $0.01 per 5KB. Write a program that calculates a customer's monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of KB of data that were used. It should then display the total charges.**/ import javax.swing.JOptionPane; public class Phone { public static void main (String []args) { String pack = ""; String input = ""; int data = 0; double bill = 0; //Ask the user to enter their package plan pack = JOptionPane.showInputDialog(null, "Please enter your package plan."); //Ask the user to enter how many KB's were used input = JOptionPane.showInputDialog(null, "How many KB's were used this month?"); data = Integer.parseInt (input); char p = pack.charAt(0); switch (p) { case 'a': if ((data > (50 * 1024))){ int extra = data - (50 * 1024); bill = 5 + (extra * .01/5); } else { bill = 5; } break; case 'b': if ((data > (200 * 1024))){ int extra = data - (200 * 1024); bill = 15 + (extra * .01/5); } else{ bill = 15; } break; case 'c': if (data > 1024){ int extra = data - (1024 * 1024); bill = 25

Get Access