Write a program that calculates and prints the bill for a cellulartelephone comp
ID: 3614001 • Letter: W
Question
Write a program that calculates and prints the bill for a cellulartelephone company. The company offers two types of service: regularand premium. Rates vary based on the type of service and arecomputed as follows:Regular service: $10.00 plus first 50 minutes are free. Charges forover $50 minutes are $.20 per minute.
Premium service: $25.00 plus:
a. For calls made from 6 am to 6 pm, the first 75 minutes are free;charges for over 75 minutes are .10 per minute.
b. For calls made from 6pm to 6 am, the first 100 minutes are free;charges for 100 minutes are $0.05 per minute.
Your program should prompt the user to enter an account number, aservice code (type char), and the number of minutes the service wasused. A service code of r or R means regular service; a servicecode of p or P means premium service. Treat any other character asan error. Your program should output the account number, type ofservice, number of minutes the telephone service was used, and theamount due from the user. For the premium service, the customer maybe using the service during the day and the night. Therefore, tocalculate the bill,you must ask the user to input the number ofminutes the service was used during the day and the number ofminutes the service was used during the night.
Explanation / Answer
please rate - thanks import java.util.*; public class PhoneBill{ public static void main(String args[]){ String accountNumber = ""; char serviceCode = ' '; int numMinUsed = 0; int over=0; int minDay = 0, minNight = 0; double bill = 0.0; String temp; System.out.println("Please enter your account number:"); Scanner s = new Scanner(System.in); accountNumber = s.next(); System.out.println("Please enter service code: (R/P only)"); temp=s.next(); serviceCode=temp.charAt(0); if (serviceCode == 'P'){ System.out.println("Enter minutes used duringday:"); minDay = s.nextInt(); System.out.println("Enter minutes used duringnight:"); minNight = s.nextInt(); System.out.println(" Account #: " +accountNumber); System.out.println("Service type: " +serviceCode); System.out.println("Minutes used during Day: " +minDay); System.out.println("Minutes used during Night: "+ minNight); bill=25; if(minDay >75){ over = minDay - 75; bill =bill+ over * .10; } if(minNight > 100){ over = minNight -100; bill =bill+ over * .05; } } else{ System.out.println("Enter minutes used:"); numMinUsed = s.nextInt(); System.out.println(" Account #: " +accountNumber); System.out.println("Service type: " +serviceCode); bill =10; if(numMinUsed > 50) { over = numMinUsed- 50; bill =bill+ over *.20; } } System.out.println("Your total bill is: $" + bill + "0"); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.