Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.38 KB | None | 0 0
  1. // Assignment Members
  2.  
  3. // Name ID Problem Description
  4.  
  5. // Mostafa Esmail 20180275 #3 (+Biased) Integrating the two classes together into ArrayList.
  6. // Omar Abdelaziz 20180178 #1 (+2D Array) Creating Class Account and its Derived Class aka Class Special Account.
  7. // Youssef Gamal 20180340 #2 (+Queue) Creating Class Client and its Derived Class aka Class Commercial Account.
  8.  
  9. // Date 2020/2/22
  10.  
  11. package com.company;
  12.  
  13. import java.util.Scanner;
  14.  
  15. public class Main {
  16. public static void main(String[] args) {
  17.  
  18. Scanner input = new Scanner(System.in);
  19.  
  20. // Bonus Part - 2D Array
  21.  
  22. /*
  23. System.out.println("2D Array Problem");
  24. Array2D ArrayTwoDimensional= new Array2D(3,3);
  25.  
  26. // [0][0:2] , [1][0:2] , [2][0:2]
  27. // { {42,23,61} , {36,94,85} , {15,39,40} }
  28.  
  29. for(int i=0;i<3;i++)
  30. {
  31. for(int j=0;j<3;j++)
  32. {
  33. System.out.println("ArrayTwoDimensional" + "["+ i + "]"+"["+j+"]" + " : ");
  34. ArrayTwoDimensional.add(i,j,input.nextInt());
  35. }
  36. }
  37. for(int i=0;i<3;i++){
  38. for(int j=0;j<3;j++)
  39. System.out.println("ArrayTwoDimensional" + "["+ i + "]"+"["+j+"]" + " : " + ArrayTwoDimensional.Fetch(i,j));
  40. }
  41.  
  42. */
  43.  
  44. // Bonus Part - Implementing Queue using Class Array - Composition
  45.  
  46. /*
  47. System.out.println("Queue Problem");
  48. Queue QueueMe = new Queue(4); // QueueMe consists of 4 elements
  49.  
  50. // Adding values to the Queue
  51. QueueMe.Queueing(2);
  52. QueueMe.Queueing(4);
  53. QueueMe.Queueing(6);
  54. QueueMe.Queueing(8);
  55.  
  56. //Checking if it's full
  57. if(QueueMe.IsFull()) System.out.println("QueueMe is Full");
  58. else System.out.println("QueueMe still has some space.");
  59.  
  60. //Checking if it's empty
  61. if(QueueMe.IsEmpty()) System.out.println("QueueMe is empty");
  62. else System.out.println("QueueMe is not empty");
  63. // Trying to add element.
  64.  
  65. QueueMe.Queueing(10); // cannot add new element to the queue because it's full.
  66.  
  67. */
  68.  
  69. // Bonus Part - Group Task
  70.  
  71. /*
  72. System.out.println("1D Array Problem - Group Task");
  73. Array ArrayOneDimensional = new Array(3);
  74.  
  75. for(int i=0; i < ArrayOneDimensional.ArraySize() ; i++ ){
  76. System.out.println("ArrayOneDimensional"+"["+i+"] : ");
  77. ArrayOneDimensional.addElement(i,input.nextInt());
  78. }
  79.  
  80. for(int i=0; i < ArrayOneDimensional.ArraySize() ; i++ ){
  81. System.out.println("ArrayOneDimensional"+"["+i+"] : " + ArrayOneDimensional.elementAt(i));
  82. }
  83.  
  84. ArrayOneDimensional.ensure(4); // extend the array to contain 4 elements instead of 3 .
  85.  
  86. ArrayOneDimensional.addElement(3,23);
  87.  
  88. for(int i=0; i < ArrayOneDimensional.ArraySize() ; i++ ){
  89. System.out.println("ArrayOneDimensional"+"["+i+"] : " + ArrayOneDimensional.elementAt(i));
  90. }
  91. */
  92.  
  93. // Bonus Part - Biased Array
  94.  
  95. /*
  96. System.out.println("Biased Array Problem");
  97.  
  98. int bias = 2;
  99. int size = 4;
  100. int upperLimit= bias+size;
  101. Array biased =new Biased_Array(size,bias);
  102.  
  103. for(int i=bias;i<upperLimit;i++){
  104. System.out.println("biased"+"["+i+"] : " );
  105. biased.addElement(i,input.nextInt());
  106. }
  107. for(int i=bias;i<upperLimit;i++)
  108. System.out.println("biased"+"["+i+"] : "+ biased.elementAt(i));
  109.  
  110. biased.addElement(2,25);
  111.  
  112. for(int i=bias;i<upperLimit;i++)
  113. System.out.println("biased"+"["+i+"] : "+ biased.elementAt(i));
  114.  
  115. */
  116.  
  117. // Main Task - Bank problem
  118.  
  119. String BankName="", BankAddress="", BankPhone="";
  120.  
  121. System.out.println("Bank Name : " );
  122. BankName = input.nextLine();
  123. System.out.println("Address : " );
  124. BankAddress = input.nextLine();
  125. System.out.println("Phone : " );
  126. BankPhone = input.next();
  127.  
  128. Bank BankObject = new Bank(BankName, BankAddress, BankPhone); // Creating a Bank object and passing arguments to the parameterized constructor
  129.  
  130. System.out.println("\n\t" + "Welcome in " + BankObject.name_getter() + "\n");
  131.  
  132. int menuChoice = 0;
  133. int Account_Number=0;
  134.  
  135. do {
  136. System.out.println("1. Add a new client");
  137. System.out.println("2. Show all accounts");
  138. System.out.println("3. Withdraw");
  139. System.out.println("4. Deposit");
  140. System.out.println("5. Display bank information");
  141. System.out.println("6. Edit bank information");
  142. System.out.println("7. Delete Client from Bank's Database");
  143. System.out.println("8. Exit");
  144.  
  145. System.out.println("Choice : ");
  146.  
  147. menuChoice = input.nextInt();
  148.  
  149. input.nextLine();
  150.  
  151. switch (menuChoice) {
  152. case 1: {
  153. int typeClientMenu, typeAccountMenu; // Integer Values used to indicate typeClient either it's Normal or Commercial
  154. // typeAccount either it's Normal or Special
  155.  
  156. System.out.println("Are you a Normal client or Commercial Client?");
  157. do {
  158. System.out.println("1. Normal Client \n2. Commercial Client \n3. Return to the main menu\n\nChoice : ");
  159. typeClientMenu = input.nextInt();
  160.  
  161. if (typeClientMenu==3) break; // Break from the loop
  162.  
  163. } while (typeClientMenu != 1 && typeClientMenu != 2);
  164. input.nextLine();
  165.  
  166. if(typeClientMenu==3) break; // Break from the case
  167.  
  168. System.out.println("Do you want Normal Account or Special Account?");
  169.  
  170. do {
  171. System.out.println("1. Normal Account \n2. Special Account \n3. Return to the main menu\n\nChoice : ");
  172. typeAccountMenu = input.nextInt();
  173. if (typeAccountMenu==3) break; // Break from the loop
  174.  
  175. } while (typeAccountMenu != 1 && typeAccountMenu != 2);
  176. input.nextLine();
  177.  
  178. if (typeAccountMenu==3) break; // Break from the case
  179.  
  180. // workaround to fix some problem occurs when input is skipped after entering an integer value
  181.  
  182. String Name = "", Address = "", Phone = "", NationalID = "", CommercialID = "";
  183.  
  184. System.out.println("Name (or Company Name) : ");
  185. Name = input.nextLine();
  186.  
  187. if (typeClientMenu == 1) {
  188. System.out.println("National ID : ");
  189. NationalID = input.next();
  190. }
  191.  
  192. if (typeClientMenu == 2) {
  193. System.out.println("Commercial ID: ");
  194. CommercialID = input.next();
  195. }
  196. input.nextLine();
  197.  
  198. System.out.println("Address : ");
  199. Address = input.nextLine();
  200. System.out.println("Phone Number : ");
  201. Phone = input.next();
  202.  
  203. Account ClientAccount = typeAccountMenu == 1 ? new Account() : new Special_Account();
  204. Client ClientObject = typeClientMenu == 1 ? new Client(Name, NationalID, Address, Phone, ClientAccount) : new CommercialClient(Name, CommercialID, Address, Phone, ClientAccount);
  205. // Creating two objects, One client object and the other is account object to be passed in their Constructors based on the information above.
  206. // I used ternary operator as a conditional statement to make the statement look clear and simple ( if -- then -- formula )
  207.  
  208. BankObject.addData(ClientObject); // adding Client to the BankDatabase
  209.  
  210. System.out.println("A Client has been added to the Bank Database and his Account Number is " + ClientObject.getClient_account().getAccount_number());
  211. }
  212. break;
  213. case 2:
  214. System.out.println("Number of Clients in the Bank : " + BankObject.NumberOfClients() + "\n");
  215. BankObject.displayData();
  216. break;
  217. case 3:
  218. if (BankObject.NumberOfClients() == 0)
  219. System.out.println("No accounts exist in the database");
  220. else {
  221. System.out.println("Account Number : ");
  222. Account_Number = input.nextInt();
  223. BankObject.ManipulateBalance(Account_Number, 'W');
  224. }
  225. break;
  226. case 4:
  227. if (BankObject.NumberOfClients() == 0)
  228. System.out.println("No accounts exist in the database");
  229. else {
  230. System.out.println("Account Number : ");
  231. Account_Number = input.nextInt();
  232. BankObject.ManipulateBalance(Account_Number, 'D');
  233. }
  234. break;
  235. case 5:
  236. System.out.println(BankObject);
  237. System.out.println("\n");
  238. break;
  239. case 6: {
  240. int editChoiceMenu = 0;
  241. String Edit = "";
  242.  
  243. do {
  244. System.out.println("1. Edit Name ");
  245. System.out.println("2. Edit Address ");
  246. System.out.println("3. Edit Phone ");
  247. System.out.println("4. Return to the main menu");
  248. System.out.println("\nChoice : ");
  249. editChoiceMenu = input.nextInt();
  250.  
  251. if (editChoiceMenu==4) break; // break from the loop
  252. } while (editChoiceMenu != 1 && editChoiceMenu != 2 && editChoiceMenu != 3);
  253.  
  254. if (editChoiceMenu==4) break; // break from the case
  255.  
  256. input.nextLine();
  257.  
  258. if (editChoiceMenu == 1) {
  259. System.out.println("Old Bank Name : " + BankObject.name_getter());
  260. System.out.println("New Bank Name : ");
  261. Edit = input.nextLine();
  262.  
  263. BankObject.name_setter(Edit);
  264. System.out.println("Bank Name has been changed!");
  265.  
  266. } else if (editChoiceMenu == 2) {
  267. System.out.println("Old Bank Address : " + BankObject.address_getter());
  268. System.out.println("New Bank Address : ");
  269. Edit = input.nextLine();
  270.  
  271. BankObject.address_setter(Edit);
  272. System.out.println("Bank Address has been changed!");
  273.  
  274. } else {
  275. System.out.println("Old Bank Phone Number : " + BankObject.phone_getter());
  276. System.out.println("New Bank Phone Number : ");
  277. Edit = input.nextLine();
  278.  
  279. BankObject.phone_setter(Edit);
  280. System.out.println("Bank Phone Number has been changed!");
  281. }
  282. }
  283. break;
  284. case 7:
  285. if (BankObject.NumberOfClients() == 0)
  286. System.out.println("No accounts exist in the database");
  287. else {
  288. int accountNumber;
  289. System.out.println("Account Number : ");
  290. accountNumber = input.nextInt();
  291. input.nextLine();
  292. BankObject.deleteClientFromDatabase(accountNumber);
  293. }
  294. break;
  295. case 8:
  296. System.out.println("Thanks for using the program.");
  297. break;
  298. default:
  299. System.out.println("Wrong Input");
  300. }
  301. } while (menuChoice != 8);
  302.  
  303.  
  304. } // End of Main()
  305. } // End of Class Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement