Advertisement
woofingfox

updateboiz

Nov 18th, 2019
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. Main
  2.  
  3. public static void main(String[] args) throws IOException{
  4. Scanner sc = new Scanner(System.in);
  5. Bank_Transact bt = new Bank_Transact();
  6. bt.storeInfo();
  7. bt.enterPin();
  8. bt.menu();
  9. }
  10.  
  11. Bank_Transact
  12.  
  13. public void menu() throws IOException{
  14. System.out.println("Welcome to Power Bank");
  15. System.out.println("[B] Balance Inquiry");
  16. System.out.println("[W] Withdraw");
  17. System.out.println("[D] Deposit");
  18. System.out.println("[X] Exit");
  19. char choice = sc.next().charAt(0);
  20. options(choice, infoPin);
  21. }
  22. public void options(char c, String p) throws IOException{
  23. FileWriter f2 = new FileWriter("C:\\Users\\DELL\\Desktop\\CUST.txt");
  24. char ans;
  25. switch(c){
  26. case 'b':
  27. case 'B':
  28. inf.forEach(in -> {
  29. if(p.equals(in.getPin()))
  30. System.out.println("The current is PHP " + df.format(Double.parseDouble(in.getDeposit())));
  31. });
  32. System.out.print("Do you want to do another transaction[y/n]? ");
  33. ans = sc.next().charAt(0);
  34. if(ans == 'y' || ans == 'Y'){
  35. menu();
  36. }
  37. else
  38. System.exit(0);
  39. break;
  40. case 'w':
  41. case 'W':
  42. inf.forEach(in -> {
  43. if(p.equals(in.getPin())){
  44. System.out.print("Enter the amount to be withdrawn: ");
  45. int withdraw = sc.nextInt();
  46. double tempW = Double.valueOf(in.getDeposit()) - withdraw;
  47. in.setDeposit(Double.toString(tempW));
  48. }
  49. });
  50. System.out.print("Do you want to do another transaction[y/n]? ");
  51. ans = sc.next().charAt(0);
  52. if(ans == 'y' || ans == 'Y'){
  53. menu();
  54. }
  55. else
  56. System.exit(0);
  57. break;
  58. case 'd':
  59. case 'D':
  60. inf.forEach(in -> {
  61. if(p.equals(in.getPin())){
  62. System.out.println("This machine accepts bills only.");
  63. System.out.print("Enter deposit amount: ");
  64. double dep = sc.nextDouble();
  65. double tempB = Double.parseDouble(in.getDeposit()) + dep;
  66. in.setDeposit(Double.toString(tempB));
  67. }
  68. });
  69. System.out.print("Do you want to do another transaction[y/n]? ");
  70. ans = sc.next().charAt(0);
  71. if(ans == 'y' || ans == 'Y'){
  72. menu();
  73. }
  74. else
  75. System.exit(0);
  76. break;
  77. case 'x':
  78. case 'X':
  79. for(InfoClass in : inf) {
  80. System.out.println(in.getPin() + "\t" + in.getName() + "\t" + df.format(Double.parseDouble(in.getDeposit())));
  81. f2.write(in.getPin());
  82. f2.write(System.getProperty( "line.separator" ));
  83. f2.write(in.getName());
  84. f2.write(System.getProperty( "line.separator" ));
  85. f2.write(in.getDeposit());
  86. f2.write(System.getProperty( "line.separator" ));
  87. }
  88. f2.close();
  89. }
  90. }
  91.  
  92. InfoClass
  93.  
  94. protected String pin;
  95. protected String name;
  96. protected String deposit;
  97. public InfoClass(){
  98. pin = "";
  99. name = "";
  100. deposit = "";
  101. }
  102. public InfoClass(String pin, String name, String deposit){
  103. this.pin = pin;
  104. this.name = name;
  105. this.deposit = deposit;
  106. }
  107. public String getPin(){
  108. return pin;
  109. }
  110. public void setPin(String pin){
  111. this.pin = pin;
  112. }
  113. public String getName(){
  114. return name;
  115. }
  116. public void setName(String name){
  117. this.name = name;
  118. }
  119. public String getDeposit(){
  120. return deposit;
  121. }
  122. public void setDeposit(String deposit){
  123. this.deposit = deposit;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement