Question

IN JAVA PLEASE Design (pseudocode) and implement (source code) a program (name it PhoneBill) that calculates...

IN JAVA PLEASE Design (pseudocode) and implement (source code) a program (name it PhoneBill) that calculates the bill for a cellular telephone company. The company offers two types of service: regular service and premium service. The rates vary depending on the type of service. The rates are computed as follows: Regular service: $15.00 fee covering first 50 minutes. Charges for over 50 minutes are computed at the rate of $0.50 per minute. Premium service: $25.00 fee plus: a. For daytime calls (between 6:00AM to 6:00PM), the first 50 minutes are free; charges for over 50 minutes are computed at the rate of $0.20 per minute. b. For nighttime calls (between 6:00PM to 6:00AM), the first 100 minutes are free; charges for over 100 minutes are computed at the rate of 0.10 per minute. The program prompts the user to enter an account number, a service code (of type char), and the number of minutes the service was used. A service code r (or R) means regular service; while code p (or P) means premium service. If the service is premium (code p or P), the customer may be using the service during both the day and night. Therefore, the program must ask the user to input the number of minutes used during daytime and nighttime in separate prompts. Document your code and properly label the input prompts and the outputs as shown below. Sample run 1: Account Number: 12345 Service type: Regular Total minutes: 50 Amount due: $15.00 Sample run 2: Account Number: 32145 Service type: Premium Daytime minutes: 40 Nighttime minutes: 200 Amount due: $35.00 Sample run 3: Account Number: 78654 Service type: Premium Daytime minutes: 60 Nighttime minutes: 120 Amount due: $29.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the solution:

package HomeworkLib;

import java.util.Scanner;

public class PhoneBill {
   // declare the constant variable for the day,night call rates and minutes
   final static double REG_CHARGES = 15.00;
   final static int REG_MINUTES = 50;
   final static double REG_RATE_OVER_50 = 0.50;

   final static double PREM_SERV_CHARGES = 25.00;
   final static int PREM_FREE_DAY_MINUTES = 50;
   final static double PREM_DAY_RATE_OVER_50 = 0.20;

   final static int PREM_FREE_NIGHT_MINUTES = 100;
   final static double PREM_NIGHT_RATE_OVER_100 = 0.10;

   static Scanner input = new Scanner(System.in); // scanner object for input

   public static void main(String[] args) {
       // declare for input and calculate the due amount
       int account;
       char service_type;
       double amount_due = 0;

       System.out.print("Enter Account Number :"); // input account number
       account = input.nextInt();

       System.out.print("Enter Service Type:R or r (Regular Service) P or p (Premium Service): "); // enter service
                                                                                                   // type
       service_type = input.next().charAt(0);

       switch (service_type) { // switch case for select service type
       case 'r':
       case 'R':

           amount_due = regular(); // call the function to calculate the regular amount due
           // print the account number and due amount
           System.out.println("Account Number: " + account);
           System.out.println("Amount Due: $" + amount_due);
           break;
       case 'p':
       case 'P':

           amount_due = premium(); // call the function to calculate the premium amount due
           // print the account number and due amount
           System.out.println("Account Number: " + account);
           System.out.println("Amount Due: $" + amount_due);
           break;
       default:
           System.out.println("Invalid customer type."); // if invalid customer type
       }
   }

   // method for calculate the regular
   static double regular() {
       int minutes; // input minutes from user
       double bAmount; // calullate the due amount variable

       System.out.print("Enter Number of Minutes"); // input minutes
       minutes = input.nextInt();

       while (minutes < 0) { // enter minut if less than 0
           System.out.print("Enter Number of Minutes");
           minutes = input.nextInt();
       }
       // calculate the regular minute
       if (minutes <= REG_MINUTES)
           bAmount = REG_CHARGES;
       else
           bAmount = REG_CHARGES + (minutes - REG_MINUTES) * REG_RATE_OVER_50;
       System.out.println("Service Type: Regular");

       return bAmount;
   }

   // method for calculate the premium
   static double premium() {
       int day_minutes, night_minutes; // input minutes for day and night from user variable
       double bAmount;

       // input minutes for day and night from user
       System.out.print("Enter day time minutes used: ");
       day_minutes = input.nextInt();

       System.out.print("Enter night time minutes used: ");
       night_minutes = input.nextInt();

       bAmount = PREM_SERV_CHARGES;

       if (day_minutes > PREM_FREE_DAY_MINUTES)
           bAmount = bAmount + (day_minutes - PREM_FREE_DAY_MINUTES) * PREM_DAY_RATE_OVER_50;

       if (night_minutes > PREM_FREE_NIGHT_MINUTES)
           bAmount = bAmount + (night_minutes - PREM_FREE_NIGHT_MINUTES) * PREM_NIGHT_RATE_OVER_100;

       System.out.println("Service Type: Premium");
       System.out.println("Minutes Service Used (Day): " + day_minutes);
       System.out.println("Minutes Service Used (Night): " + night_minutes);

       return bAmount;

   }

}

output:

Enter Account Number :12345
Enter Service Type:R or r (Regular Service) P or p (Premium Service): r
Enter Number of Minutes:50
Service Type: Regular
Account Number: 12345
Amount Due: $15.0

Enter Account Number :32145
Enter Service Type:R or r (Regular Service) P or p (Premium Service): p
Enter day time minutes used: 40
Enter night time minutes used: 200
Service Type: Premium
Minutes Service Used (Day): 40
Minutes Service Used (Night): 200
Account Number: 32145
Amount Due: $35.0

Enter Account Number :78654
Enter Service Type:R or r (Regular Service) P or p (Premium Service): P
Enter day time minutes used: 60
Enter night time minutes used: 120
Service Type: Premium
Minutes Service Used (Day): 60
Minutes Service Used (Night): 120
Account Number: 78654
Amount Due: $29.0

Add a comment
Know the answer?
Add Answer to:
IN JAVA PLEASE Design (pseudocode) and implement (source code) a program (name it PhoneBill) that calculates...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE DO THIS IN JAVA!Design (pseudocode) and implement (source code) a program (name it PhoneBill) that...

    PLEASE DO THIS IN JAVA!Design (pseudocode) and implement (source code) a program (name it PhoneBill) that calculates the bill for a cellular telephone company. The company offers two types of service: regular service and premium service. The rates vary depending on the type of service. The rates are computed as follows: Regular service: $15.00 fee covering first 50 minutes. Charges for over 50 minutes are computed at the rate of $0.50 per minute. Premium service: $25.00 fee plus: a. For...

  • Do pseudocode in java Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that...

    Do pseudocode in java Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and number of times it appeared as shown...

  • IN PYTHON ONLY !! Design (pseudocode) and implement (source code) a program (name it Occurrences) to...

    IN PYTHON ONLY !! Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. - The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true...

  • PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code)...

    PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document...

  • Design (pseudocode) and implement (source code) a program (name it IncomeTax) that reads from the user...

    Design (pseudocode) and implement (source code) a program (name it IncomeTax) that reads from the user annual income, as integer value, and calculates the income tax based on the tax table below. Income Tax bracket Annual income <= $50,000 5% $50,000 < Annual income <= $200,000 10% $200,000 < Annual income <= $400,000 15% $400,000 < Annual income <= $900,000 25% $900,000 < Annual income 35% The program output should include the entered annual income followed by the applied tax...

  • PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name...

    PSEUDOCODE and PYTHON source code! Program 4: Design (pseudocode) and implement (source code) a program (name it MinMaxAvg) to determine the highest grade, lowest grade, and the average of all grades in a 4-by-4 two-dimensional arrays of integer grades (representing 4 students’ grades on 4 tests). The program main method populates the array (name it Grades) with random grades between 0 and 100 and then displays the grades as shown below. The main method then calls method minMaxAvg()that takes a...

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

  • : Design (pseudocode) and implement (source code) a program (name it Circles) to determine if a...

    : Design (pseudocode) and implement (source code) a program (name it Circles) to determine if a circle is either completely inside, overlapping with, or completely outside another circler. The program asks the user to enter the center point (X1, Y1) and the radius (R1) for the first circle C1, and the center point (X2, Y2) and the radius (R2) for the second circle C2. The program then determines if the second circle C2 is either completely inside, or overlapping with,...

  • please do the program in simple programming it is for my first c++ computer class i...

    please do the program in simple programming it is for my first c++ computer class i posted the example on pic 2,3 which is how this should be done Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus the first 50 minutes are free. Charges for...

  • Design Java (source code) a program (name it IndexOfLargest) to find the index of the first...

    Design Java (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional array of integer values and return the index of the first...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT