Question: Write a Java program that calculates and prints the bill for a cellular telephone company. The company uses the following plans: (a) Premium Service:

Write a Java program that calculates and prints the bill for a cellular telephone company. The company uses 3. How do you check the service code?  The user may enter any string.  Your code should only accept the String upCaseServiceCode = serviceCode.toUpperCase(); The statement takes the service code stored in the

Write a Java program that calculates and prints the bill for a cellular telephone company. The company uses the following plans: (a) Premium Service: $25 plus (1) For day minutes (6:00 AM to 6:00 PM), the first 75 minutes are free; charges for over 75 minutes are $0.10 per minutes. (2) For night minutes (6:00 PM to 6:00 AM), the first 100 minutes are free; charges over 100 minutes are $0.05 per minute. (b) Regular Service: $10.00 plus first 50 minutes are free; charges over 50 minutes are $0.20 per minute. Input The input for the program must be the following: Account Number Customer Name Service code (Premium or Regular) For Premium service: Number of Day minutes and Number of Night Minutes. Note that we are not asking the user the time when they made the call. You can use either the console or the JOptionPane to input the data. Frequently Asked Questions 1. How do you input a name that has multiple words like Mary Smith? You can use the method nextLine(). nextLine input a line of input for example the code: String name = console.nextLine(); will input a multiple words input. 2. What should the program output? Your program should output the customer name, account number, followed by the plan, minutes used, and bill total. See the sample run at the end of this document. 3. How do you check the service code? The user may enter any string. Your code should only accept the strings Premium or Regular and reject any other string as error. The use may enter the code lowercase, uppercase or mixed. The following codes are all valid: premium, PRemium, REGular, regulAR. The following strings are all invalid: Premum, reguler, Prem, reg, 123, help 4. What do you do if the user input Premium or Regular with lowercase letters or mixed letters (For example, premium, regular, or Regular)? Use equalsignoreCase() method instead of equals method or compareTolgnoreCase() method instead of compare To 5. What logic should the skeleton on my program follow? You can use an if statement: if (service code is premium){ do all the calculation for premium service in this block } else if(service code is regular){ do all the calculation for regular service in this block } else { the service code must be error; user entered other than regular or premium } Instead of an if statement as shown above, you can also use a switch statement. Here is the skeleton for a switch statement: switch (service code){ case: "REGULAR" : all code for regular goes here; break; case: "PREMIUM": all code for premium goes here; break; default: must be error. } Note: The switch statement requires you to upper case the service code. You can do that using the method toUpperCase(). Here is an example: String upCaseServiceCode = serviceCode.toUpperCase(); The statement takes the service code stored in the variable serviceCode and changes it to upper case and stores the result in the variable upCaseServiceCode. Sample Run Enter the account number: 1116 Enter the service type: regular or premium: PREMIUM Enter the daytime minutes used: 76 Enter the nighttime minutes used: 101 Account Number: 1116. Service Type: Premium Minutes Service Used (Day): 76 Minutes Service Used (Night): 101 Amount Due: $25.15 Enter the account number: 1111 Enter the service type: regular or premium: Regular Enter the number of minutes service used: 51 Account Number: 1111 Service Type: Regular Minutes Service Used: 51 Amount Due: $10.20 Enter the account number: 1112 Enter the service type: regular or premium: PreMiuM Enter the daytime minutes used: 75 Enter the nighttime minutes used: 100 Account Number: 1112 Service Type: Premium Minutes Service Used (Day): 75 Minutes Service Used (Night): 100 Amount Due: $25.00 Enter the account number: 1113 Enter the service type: regular or premium: regular/premium Invalid Service Type. Enter the account number: 1115 Enter the service type: regular or premium: Help Invalid Service Type.

Step by Step Solution

3.50 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Java program that calculates and prints the bill for a cellular telephone company TelephoneCompanyja... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!