Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tumacay_bank;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.FileReader;
  10. import java.io.IOException;
  11. import java.util.ArrayList;
  12. import java.util.Iterator;
  13. import java.util.Objects;
  14. import java.util.Scanner;
  15.  
  16. /**
  17. *
  18. * @author S202-11
  19. */
  20. public class Tumacay_Bank {
  21.  
  22. /**
  23. * @param args the command line arguments
  24. */
  25.  
  26. //static Scanner input;
  27.  
  28. static int SampleAccountNo = 12345;
  29. static int SampleAccountPIN = 1234;
  30. static int SampleAccountCash = 20000;
  31. static double Cash;
  32.  
  33. static Scanner input;
  34.  
  35. static ArrayList<String> ValidAccountNos;
  36.  
  37. public static void main(String[] args) throws IOException {
  38. // TODO code application logic here
  39.  
  40. /* LOAD THE DATABASE */
  41. ValidAccountNos = new ArrayList<String>();
  42.  
  43. try (BufferedReader br = new BufferedReader(new FileReader("database.txt"))) {
  44. String line;
  45. while ((line = br.readLine()) != null) {
  46. //System.out.println(line);
  47. if( contains( line, "[DATA]")) {
  48. //System.out.println( "Found [DATA] within " + line + "." );
  49. String[] parts = line.split(",");
  50. ValidAccountNos.add(parts[2]);
  51. }
  52. // process the line.
  53. }
  54. }
  55.  
  56.  
  57.  
  58. // int twoDimenArray[][] = new int[3][5];
  59. // int i, j, k = 0;
  60. //
  61. // for(i = 0; i < 3; i++) {
  62. // for(j = 0; j < 5; j++) {
  63. // twoDimenArray[i][j] = k;
  64. // k++;
  65. // }
  66. // }
  67.  
  68.  
  69. // for(Iterator<String> i = ValidAccountNos.iterator(); i.hasNext(); ) {
  70. // String item = i.next();
  71. // System.out.println(item);
  72. // }
  73.  
  74.  
  75. //String[] AccountName;
  76. // for(int NoOfPeople = 1; NoOfPeople <= 10; NoOfPeople++) {
  77. // String[] AccountName = null;
  78. //
  79. // AccountName[NoOfPeople] = "Juan Tamad";
  80. // System.out.println(AccountName[NoOfPeople]);
  81. // //int[] AccountNo = {12345};
  82. // }
  83.  
  84.  
  85. //Home();
  86.  
  87. //ERROR
  88. // int AccountNoErrorCount = 0, AccountNoInput;
  89. //
  90. // while(AccountNoErrorCount <= 2)
  91. // {
  92. // AccountNoErrorCount++;
  93. // System.out.println("Account No: ");
  94. //
  95. // AccountNoInput = input.nextInt();
  96. // System.out.println("No. of tries: " + AccountNoErrorCount);
  97. // }
  98.  
  99.  
  100.  
  101.  
  102. }
  103.  
  104. public static void Home() {
  105. System.out.println("\n Welcome to LPU Bank System.\n");
  106.  
  107. input = new Scanner(System.in);
  108.  
  109. //int AccountNoInput = input.nextInt();
  110.  
  111.  
  112. System.out.println("[TRANSACTION]");
  113. System.out.println("1. Deposit");
  114. System.out.println("2. Withdraw");
  115. System.out.println("3. Balance Inquiry");
  116. System.out.println("4. Exit");
  117. System.out.println("\nOption: ");
  118. int Option = input.nextInt();
  119.  
  120. switch(Option) {
  121. case 1:
  122. System.out.println("[DEPOSIT TRANSACTION]");
  123. System.out.println("Cash: ");
  124. Cash = input.nextDouble();
  125. Deposit(SampleAccountNo, Cash);
  126. break;
  127. case 2:
  128. System.out.println("[WITHDRAW TRANSACTION]");
  129. System.out.println("Cash: ");
  130. Cash = input.nextDouble();
  131. Withdraw(SampleAccountNo, Cash);
  132. break;
  133. case 3:
  134. BalanceInquiry(SampleAccountNo);
  135. break;
  136. case 4:
  137. Exit();
  138. break;
  139. default:
  140. System.out.println("\nINVALID OPTION!");
  141. Home();
  142. break;
  143. }
  144.  
  145. }
  146.  
  147. public static void Deposit(int AccountNo, double Cash) {
  148. //AccountNo += Cash;
  149. SampleAccountCash += Cash;
  150. System.out.println("[RECEIT RECEIPT]");
  151. System.out.println("Account Name: " + "Sample Account Name");
  152. System.out.println("Account No.: " + AccountNo);
  153. System.out.println("Balance: " + (SampleAccountCash - Cash));
  154. System.out.println("Deposit: " + Cash);
  155. System.out.println("New Balance: " + SampleAccountCash);
  156. Home();
  157. }
  158.  
  159. public static void Withdraw(int AccountNo, double Cash) {
  160. //AccountNo -= Cash;
  161. SampleAccountCash -= Cash;
  162. System.out.println("[WITHDRAW RECEIPT]");
  163. System.out.println("Account No.: " + AccountNo);
  164. System.out.println("Balance: " + (SampleAccountCash + Cash));
  165. System.out.println("Withdraw: " + Cash);
  166. System.out.println("New Balance: " + SampleAccountCash);
  167. Home();
  168. }
  169.  
  170. public static void BalanceInquiry(int AccountNo) {
  171. System.out.println("[BALANCE INQUIRY]");
  172. System.out.println("Account No.: " + AccountNo);
  173. System.out.println("Balance: " + SampleAccountCash);
  174. Home();
  175. }
  176.  
  177. public static void Exit() {
  178. Boolean Repeat = true;
  179.  
  180. while(Repeat)
  181. {
  182. System.out.println("Do you want to make another transaction? Y or N");
  183. String RepeatInput = input.next();
  184.  
  185. switch(RepeatInput) {
  186. case "Y":
  187. Home();
  188. break;
  189. case "y":
  190. Home();
  191. break;
  192. case "N":
  193. System.exit(0);
  194. break;
  195. case "n":
  196. System.exit(0);
  197. break;
  198. default:
  199. System.out.println("\nINVALID OPTION!");
  200. Exit();
  201. break;
  202. }
  203. }
  204.  
  205. //System.exit(0);
  206. }
  207.  
  208. public static boolean contains( String haystack, String needle ) {
  209. haystack = haystack == null ? "" : haystack;
  210. needle = needle == null ? "" : needle;
  211.  
  212. // Works, but is not the best.
  213. //return haystack.toLowerCase().indexOf( needle.toLowerCase() ) > -1
  214.  
  215. return haystack.toLowerCase().contains( needle.toLowerCase() );
  216. }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement