Guest User

Untitled

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