Guest User

Untitled

a guest
Jun 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class CableCompanyBilling
  5. {
  6. static Scanner console = new Scanner(System.in);
  7.  
  8. //Named constants - residential customers
  9. static final double R_BILL_PROC_FEE = 4.50;
  10. static final double R_BASIC_SERV_COST = 20.50;
  11. static final double R_COST_PREM_CHANNEL = 7.50;
  12.  
  13. //Named constants - business customers
  14. static final double B_BILL_PROC_FEE = 15.00;
  15. static final double B_BASIC_SERV_COST = 75.00;
  16. static final double B_BASIC_CONN_COST = 5.00;
  17. static final double B_COST_PREM_CHANNEL = 50.00;
  18.  
  19. public static void main(String[] args)
  20. {
  21. //Variable declaration
  22. int accountNumber;
  23. char customerType;
  24. int noOfPremChannels;
  25. int noOfBasicServConn;
  26. double amountDue;
  27.  
  28. System.out.println("This program computes "
  29. + "a cable bill.");
  30.  
  31. System.out.print("Enter the account "
  32. + "number: "); //Step 1
  33. accountNumber = console.nextInt(); //Step 2
  34. System.out.println();
  35.  
  36. System.out.print("Enter the customer type: "
  37. + "R or r (Residential), "
  38. + "B or b(Business): "); //Step 3
  39. if (customerType == 'R' || customerType == 'r')
  40. {
  41. System.out.println(residentcust(amountDue));
  42. }
  43. else if (customerType == 'B' || customerType == 'b'){
  44. System.out.println(businesscust(amountDue));
  45. }
  46.  
  47. public static double residentcust(char r)
  48. {
  49. int noOfPremChannels;
  50. double amountDue;
  51. int accountNumber;
  52. System.out.print("Enter the number of "
  53. + "premium channels: "); //Step 5a
  54. noOfPremChannels = console.nextInt(); //Step 5b
  55. System.out.println();
  56.  
  57. amountDue = R_BILL_PROC_FEE + //Step 5c
  58. R_BASIC_SERV_COST +
  59. noOfPremChannels *
  60. R_COST_PREM_CHANNEL;
  61.  
  62. System.out.println("Account number = "
  63. + accountNumber); //Step 5d
  64. System.out.printf("Amount due = $%.2f %n",
  65. amountDue); //Step 5e
  66. return "";
  67.  
  68. }
  69.  
  70. public static double businesscust(double b)
  71. {
  72. int noOfPremChannels;
  73. double amountDue;
  74. int accountNumber;
  75. int noOfBasicServConn;
  76. System.out.print("Enter the number of "
  77. + "basic service "
  78. + "connections: "); //Step 6a
  79. noOfBasicServConn = console.nextInt(); //Step 6b
  80. System.out.println();
  81.  
  82. System.out.print("Enter the number of "
  83. + "premium channels: "); //Step 6c
  84. noOfPremChannels = console.nextInt(); //Step 6d
  85. System.out.println();
  86.  
  87. if (noOfBasicServConn <= 10) //Step 6e
  88. amountDue = B_BILL_PROC_FEE +
  89. B_BASIC_SERV_COST +
  90. noOfPremChannels *
  91. B_COST_PREM_CHANNEL;
  92. else
  93. amountDue = B_BILL_PROC_FEE +
  94. B_BASIC_SERV_COST +
  95. (noOfBasicServConn - 10) *
  96. B_BASIC_CONN_COST +
  97. noOfPremChannels *
  98. B_COST_PREM_CHANNEL;
  99.  
  100. System.out.println("Account number = "
  101. + accountNumber); //Step 6f
  102. System.out.printf("Amount due = $%.2f %n",
  103. amountDue); //Step 6g
  104. return "";
  105. }
  106. }
  107. }
Add Comment
Please, Sign In to add comment