Cable Company Billing in Java Application

This Java program application calculates and prints a customer’s bill for a local cable company. The program process two types of customers: Residential and Business. . I will be using the JCreator IDE in developing the program. To start in this tutorial, first open the JCreator IDE, click new and paste the following code.
  1. import java.util.*;
  2.  
  3. public class CableCompanyBilling
  4. {
  5. static Scanner console = new Scanner(System.in);
  6.  
  7. static final double R_BILL_PROC_FEE = 4.50;
  8. static final double R_BASIC_SERV_COST = 20.50;
  9. static final double R_COST_PREM_CHANNEL = 7.50;
  10.  
  11. static final double B_BILL_PROC_FEE = 15.00;
  12. static final double B_BASIC_SERV_COST = 75.00;
  13. static final double B_BASIC_CONN_COST = 5.00;
  14. static final double B_COST_PREM_CHANNEL = 50.00;
  15.  
  16. public static void main(String[] args)
  17. {
  18. int accountNumber;
  19. char customerType;
  20. int noOfPremChannels;
  21. int noOfBasicServConn;
  22. double amountDue;
  23.  
  24. System.out.println("This program computes cable bill");
  25.  
  26. System.out.print("Enter the account number: ");
  27. accountNumber = console.nextInt();
  28. System.out.println();
  29.  
  30. System.out.print("Enter the customer type: "
  31. + "R or (Residential), "
  32. + "B or (Business): " );
  33. customerType = console.next().charAt(0);
  34. System.out.println();
  35.  
  36. switch (customerType)
  37. {
  38. case 'r':
  39. case 'R':
  40. System.out.print("Enter the number of premium channels: ");
  41. noOfPremChannels = console.nextInt();
  42. System.out.println();
  43. amountDue = R_BILL_PROC_FEE + R_BASIC_SERV_COST + noOfPremChannels * R_COST_PREM_CHANNEL;
  44.  
  45. System.out.println("Account Number = " + accountNumber);
  46. System.out.printf("Amount Due + " + amountDue);
  47.  
  48. break;
  49.  
  50. case 'b':
  51. case 'B':
  52. System.out.print("Enter the number of basic service connections: ");
  53. noOfBasicServConn = console.nextInt();
  54. System.out.println();
  55.  
  56. System.out.print("Enter the number of premium channels: ");
  57. noOfPremChannels = console.nextInt();
  58. System.out.println();
  59.  
  60. if (noOfBasicServConn <= 10)
  61. amountDue = B_BILL_PROC_FEE + B_BASIC_SERV_COST + noOfPremChannels * B_COST_PREM_CHANNEL;
  62.  
  63. else
  64. amountDue = B_BILL_PROC_FEE + B_BASIC_SERV_COST + (noOfBasicServConn - 10) *
  65. B_BASIC_CONN_COST + noOfPremChannels * B_COST_PREM_CHANNEL;
  66.  
  67. System.out.println("Account number = " + accountNumber);
  68. System.out.printf("Amount Due = " + amountDue);
  69.  
  70. break;
  71. default:
  72.  
  73. System.out.println("Invalid customer type.");
  74.  
  75. }
  76.  
  77. }
  78.  
  79.  
  80. }
Sample run:
  1. This program computes cable bill
  2. Enter the account number: 23456
  3.  
  4. Enter the customer type: R or (Residential), B or (Business): R
  5.  
  6. Enter the number of premium channels: 40
  7.  
  8. Account Number = 23456
  9. Amount Due + 325.0
The algorithm of the program: The purpose of this program is to calculate and print the billing amount. To calculate the billing amount, you need to know the customer for whom the billing amount is calculated and the number of premium channels to which the customer subscribes. Prompts the user for the account number and customer type. Determine the number of premium channels and basic service connections, compute the bill, and print the bill based on the customer type. If the customer type is R or r, prompts the user for the number of premium channels, computes the bill and print the bill. If the customer type is B or b, prompt the user for the number of basic service connections and number of premium channels, computes the bill and print the bill.

Comments

Add new comment