grhey

Untitled

Jun 23rd, 2022
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class WaterBilling {
  3.  
  4. static String name,address;
  5. static double prevReading,currReading,sub = 0.0,due = 0.0,consumed;
  6. static int rate,yearser;
  7. static Scanner scr = new Scanner(System.in);
  8.  
  9. public static void main (String[]args){
  10.  
  11. int mainMenu = -1;
  12. while (mainMenu != 0) { //while loop for looping the menu until the user press exit
  13. menu(); //calling the menu user defined method
  14. mainMenu = scr.nextInt(); //getting user choice
  15. scr.nextLine();
  16. switch (mainMenu) {
  17. case 0:
  18. exit();
  19. break;
  20. //calling the userdefined methods
  21. case 1:
  22. add();
  23. break;
  24. //calling the userdefined methods
  25. case 2:
  26. //calling the userdefined methods
  27. case 3:
  28. display();
  29. break;//calling the userdefined methods
  30. case 4:
  31. //calling the userdefined methods
  32. default: System.out.println("Out of range");
  33. }
  34. }
  35. }
  36.  
  37. static void menu() { //the menu output
  38. System.out.println("-------[Water Billing System]-------");
  39. System.out.println("[1] Create a new user account.");
  40. System.out.println("[2] Update a current account");
  41. System.out.println("[3] Show accounts for all users.");
  42. System.out.println("[4] Try looking for an account here.");
  43. System.out.println("[0] Exit");
  44.  
  45. }
  46. static void add(){
  47. System.out.println("Name: ");
  48. name = scr.nextLine();
  49. System.out.println("Address: ");
  50. address = scr.nextLine();
  51. System.out.println("Previous Meter Reading: ");
  52. prevReading = scr.nextDouble();
  53. System.out.println("Current Meter Reading: ");
  54. currReading = scr.nextDouble();
  55. consumed = currReading - prevReading;
  56. System.out.println("[1] Residential");
  57. System.out.println("[2] Business");
  58. rate = scr.nextInt();
  59. if (rate == 1) {
  60. if (consumed > 10) {
  61. sub = 200 + ((consumed - 10) * 30);
  62. }
  63. if (consumed <= 10) {
  64. sub = 200;
  65. }
  66. } else if (rate == 2) {
  67. if (consumed > 20) {
  68. sub = 500 + ((consumed - 20) * 50);
  69. }
  70. if (consumed <= 20) {
  71. sub = 500;
  72. }
  73. System.out.println("how many years in using the service?");
  74. yearser = scr.nextInt();
  75. if (yearser >= 15 ) {
  76. due = sub - (sub * (15/100));
  77. System.out.println("15% promo discount applied!");
  78. } else {
  79. due = sub;
  80. System.out.println("No promo discount appllied!");
  81. }
  82. }
  83.  
  84.  
  85.  
  86. }
  87.  
  88. static void display(){
  89. System.out.println("Name: "+name);
  90. System.out.println("Address: "+address);
  91. System.out.println("Previous Meter Reading: "+prevReading);
  92. System.out.println("Current Meter Reading: "+currReading);
  93. System.out.println("Total Payment Due: "+due);
  94. }
  95.  
  96. static int exit() {
  97. return 0;
  98. }
  99.  
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment