Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public static double packageA = 9.95; // Package A price for a monthly subscription and before exceeding 10 hours
  4. // of service
  5. public static double packageAJ = 2.00; // price for every hour pass 10 for package A
  6. public static double packageB = 13.95;// Package B price for a monthly subscription and before exceeding 20 hours
  7. // of service
  8. public static double packageBJ = 1.00; // price for every hour pass 20 for package B
  9. public static double packageC = 19.95;
  10. public static Scanner input = new Scanner(System.in); // declares scanner as "Input"
  11.  
  12. public static void main(String[] args) {
  13. // TODO Auto-generated method stub
  14.  
  15. System.out
  16. .println("Welcome to your internet payment sitenPlease choose your packet :n" + "[Enter -1 to quit]"); // Welcoming
  17. // prompt
  18.  
  19. System.out.printf("%s%n%s%n%s%n%s%n%s", "[a] - Package A", "[b] - Package B", "[c] - Package C",
  20. "[f] - enter f to end the program", "Enter response here: "); // print format for the package options
  21. String userChoice = input.nextLine(); /// the choice that the user picks gets stored in the userChoice String
  22.  
  23. /*
  24. * this switch statement compares the choice of the user and associates it with
  25. * the correct case. Note that there is two cases with the same choice letter
  26. * "A" & "a", "B" "b" and so on. This is to ensure that no matter if the user
  27. * inputs an Upper-case or Lower-case as their answer, there wont be any issues
  28. * and the correct case would be run by the compiler
  29. */
  30. switch (userChoice) {
  31.  
  32. case "A":
  33. myFunctionA(); // Performs the function corresponding to package A
  34. // compareFunction(userChoice, packageA);
  35.  
  36. break;
  37. case "a":
  38. myFunctionA(); // Performs the function corresponding to package A
  39. // compareFunction(userChoice, packageA);
  40. break;
  41. case "B":
  42. myFunctionB(); // Performs the function corresponding to Package B
  43. // compareFunction(userChoice, packageA);
  44. break;
  45. case "b":
  46. myFunctionB(); // Performs the function corresponding to Package B
  47. // compareFunction(userChoice, packageA);
  48. break;
  49.  
  50. case "C":
  51. myFunctionC(); // Performs the function corresponding to Package C
  52. break;
  53. case "c":
  54. myFunctionC(); // Performs the function corresponding to Package c
  55. case "F":
  56. System.exit(0); // ends the program .. just like with using a sentinel value
  57. break;
  58. case "f":
  59. System.exit(0); // ends the program .. just like with using a sentinel value
  60.  
  61. }
  62.  
  63. }
  64.  
  65. /*
  66. * myfunctionA and myFunctionB hold two if statements inside their bodies. One
  67. * of the if statements is perform only when the user has not exceeded their
  68. * service time. The second If statement is only perform if the user exceeds his
  69. * use time.
  70. */
  71.  
  72. public static void myFunctionA() {
  73.  
  74. System.out.println("Enter ammount of hours use of service: "); // Prompts the user
  75. double userInput = input.nextDouble(); // saves the user input into the variable userInput
  76.  
  77. double Hours = userInput; // the number of hours the user, used the service for gets stored here
  78. double extendedHours = 0; // this variable is where the extended hours get store. for example, every hour
  79. // after 10 hours of service gets store here
  80. double regularHours = 10; // this variable holds the value of regular hours of service
  81.  
  82. if (Hours <= 10) {
  83.  
  84. System.out.println("Your total amount due is " + packageA);
  85. }
  86.  
  87. else if (Hours > 10)
  88.  
  89. {
  90.  
  91. extendedHours = Hours - regularHours; // obtains amount of Extra hours use by the client.
  92. double extendedHours2 = extendedHours * 2; // calculates the total due after multiplying the extended hours
  93. // by 2
  94. double totalAmountDue = extendedHours2 + packageA; // calculates the total amount due
  95.  
  96. System.out.println("Since you Extended your use time by " + extendedHours + " Your total amount due is "
  97. + totalAmountDue);
  98. }
  99.  
  100. }
  101.  
  102. public static void myFunctionB() {
  103.  
  104. System.out.println("Enter ammount of hours use of service: ");
  105. double userInput = input.nextDouble();
  106.  
  107. double extendedHours = 0;
  108. double regularHours = 20;
  109. double Hours = userInput;
  110.  
  111. if (Hours < 20) {
  112.  
  113. System.out.println("Your total amount due is " + packageB);
  114.  
  115. } else if (Hours > 26) {
  116.  
  117. extendedHours = Hours - regularHours; // obtains amount of Extra hours use by the client.
  118. double extendedHours2 = extendedHours * 1; // calculates the total due after multiplying the extended hours
  119. // by 1
  120. double totalAmountDue = extendedHours + packageB; // calculates the total amount due
  121. double totalSave1 = totalAmountDue - packageC;
  122.  
  123. System.out.println("Since you Extended your use time by " + extendedHours + " Your total ammount due is "
  124. + totalAmountDue);
  125.  
  126. System.out.println(
  127. "With an internet use of 26 or more hours of service, Package C would be a better plan in helping you save "
  128. + totalSave1 + " a month");
  129. }
  130.  
  131. }
  132.  
  133. /*
  134. * myFunctionC outputs the price of regular monthly use.
  135. */
  136.  
  137. public static void myFunctionC() {
  138.  
  139. System.out.println("Your ammount due for the month is: " + packageC);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement