grhey

Untitled

Jun 20th, 2022
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4.  
  5. public class FinalProject {
  6.  
  7. static ArrayList<String> name = new ArrayList<String> ();
  8. static ArrayList<String> address = new ArrayList<String> ();
  9. static ArrayList<Double> prevMreading = new ArrayList<Double> ();
  10. static ArrayList<Double> currMreading = new ArrayList<Double> ();
  11. static ArrayList<Double> Dues = new ArrayList<Double> ();
  12. static ArrayList<Double> consumption = new ArrayList<Double> ();
  13. static ArrayList<String> discount = new ArrayList<String> ();
  14. static Scanner scr = new Scanner(System.in);
  15.  
  16. public static void main(String[] args) {
  17. int mainMenu = -1;
  18. while (mainMenu != 0) {
  19. menu();
  20. mainMenu = scr.nextInt();
  21. scr.nextLine();
  22. switch (mainMenu) {
  23. case 0:
  24. exit();
  25. break;
  26. case 1:
  27. add(6);
  28. break;
  29. case 2:
  30. update();
  31. break;
  32. case 3:
  33. display();
  34. break;
  35. case 4:
  36. search();
  37. break;
  38. default:
  39. System.out.println("Out of range");
  40. break;
  41. }
  42. }
  43. }
  44.  
  45. static void menu() {
  46. System.out.println("-------[Water Billing System]-------");
  47. System.out.println("[1] Create a new user account.");
  48. System.out.println("[2] Update a current account");
  49. System.out.println("[3] Show accounts for all users.");
  50. System.out.println("[4] Try looking for an account here.");
  51. System.out.println("[0] Exit");
  52.  
  53. }
  54.  
  55. static void add(int quarter) {
  56.  
  57. String name, address;
  58. double prev, curr, due = 0.0, sub = 0.0;
  59. int rate;
  60. System.out.println("------Create a new user account!------");
  61. System.out.println("Name: ");
  62. name = scr.nextLine();
  63. FinalProject.name.add(name);
  64. System.out.println("Address: ");
  65. address = scr.nextLine();
  66. FinalProject.address.add(address);
  67. System.out.println("Previous reading: ");
  68. prev = scr.nextDouble();
  69. prevMreading.add(prev);
  70. System.out.println("Current reading: ");
  71. curr = scr.nextDouble();
  72. currMreading.add(curr);
  73. System.out.println("[1] Residential");
  74. System.out.println("[2] Business");
  75. rate = scr.nextInt();
  76. double consumed = curr - prev;
  77. consumption.add(consumed);
  78. if (rate == 1) {
  79. if (consumed > 10) {
  80. sub = 200 + ((consumed - 10) * 30);
  81. }
  82. if (consumed <= 10) {
  83. sub = 200;
  84. }
  85. } else if (rate == 2) {
  86. if (consumed > 20) {
  87. sub = 500 + ((consumed - 20) * 50);
  88. }
  89. if (consumed <= 20) {
  90. sub = 500;
  91. }
  92. }
  93. int yearser;
  94. System.out.println("how many years in using the service?");
  95. yearser = scr.nextInt();
  96. if (yearser >= 15 ) {
  97. due = sub - (sub * (15/100));
  98. discount.add("15% promo discount applied!");
  99. } else {
  100. due = sub;
  101. discount.add("No promo discount appllied!");
  102. }
  103. Dues.add(due);
  104. }
  105.  
  106. static void update() {
  107. String name, newName, newAddress;
  108. System.out.println("------Update a current account------!");
  109. System.out.println("Name: ");
  110. name = scr.nextLine();
  111. int position = 0;
  112. boolean matched = false;
  113. for (String profile : FinalProject.name) {
  114. if (profile.contains(name)) {
  115. matched = true;
  116. position = FinalProject.name.indexOf(profile);
  117. break;
  118. } else {
  119. matched = false;
  120. }
  121. }
  122. if (matched == true) {
  123. int modify;
  124. System.out.println("[1] Update name");
  125. System.out.println("[2] Update address");
  126. modify = scr.nextInt();
  127. scr.nextLine();
  128. switch (modify) {
  129. case 1:
  130. System.out.println("New name: ");
  131. newName = scr.nextLine();
  132. FinalProject.name.set(position, newName);
  133. break;
  134. case 2:
  135. System.out.println("New address: ");
  136. newAddress = scr.nextLine();
  137. address.set(position, newAddress);
  138. break;
  139. default:
  140. System.out.println("Unknown command!");
  141. break;
  142. }
  143. } else {
  144. System.out.println("No data found");
  145. }
  146. }
  147.  
  148. static void display() {
  149. System.out.println("------Show accounts for all users!------");
  150. for (int i = 0; i < name.size(); i++) {
  151. System.out.println("Name: " + name.get(i));
  152. System.out.println("Address: " + address.get(i));
  153. System.out.println("Previous reading: " + prevMreading.get(i));
  154. System.out.println("Current reading: " + currMreading.get(i));
  155. System.out.println("Current consumption: " + consumption.get(i));
  156. System.out.println("Total payment due: " + Dues.get(i));
  157.  
  158. }
  159. }
  160.  
  161. static void search() {
  162. int position = 0, searchBy;
  163. String name, address;
  164. boolean matched = false;
  165. System.out.println("------Try looking for an account here!------");
  166. System.out.println("[1] By name");
  167. System.out.println("[2] By address");
  168. searchBy = scr.nextInt();
  169. scr.nextLine();
  170. switch (searchBy) {
  171. case 1:
  172. System.out.print("Name: ");
  173. name = scr.nextLine();
  174. for (String profile : FinalProject.name) {
  175. if (profile.contains(name)) {
  176. matched = true;
  177. position = FinalProject.name.indexOf(profile);
  178. break;
  179. } else {
  180. matched = false;
  181. }
  182. } break;
  183. case 2:
  184. System.out.print("Address: ");
  185. address = scr.nextLine();
  186. for (String profile : FinalProject.address) {
  187. if (profile.contains(address)) {
  188. matched = true;
  189. position = FinalProject.address.indexOf(profile);
  190. break;
  191. } else {
  192. matched = false;
  193. }
  194. } break;
  195. default:
  196. System.out.println("Unknown command");
  197. break;
  198. }
  199.  
  200. if (matched == true) {
  201. System.out.println("Name: " + FinalProject.name.get(position) +
  202. "\nAddress: " + FinalProject.address.get(
  203. position) +
  204. "\nPrevious reading: " + prevMreading.get(position) +
  205. "\nCurrent reading: " + currMreading.get(position) +
  206. "\nCurrent consumption: " + consumption.get(position) +
  207. "\nTotal payment due: " + Dues.get(position) +
  208. "\nPromo: " + discount.get(position) +
  209. "\n"
  210. );
  211. }
  212. }
  213.  
  214. static int exit() {
  215. return 0;
  216. }
  217.  
  218. }
  219.  
Advertisement
Add Comment
Please, Sign In to add comment