Simple Bank Account Process

  1. import java.io.*;
  2. class account
  3. {
  4. int no, type;
  5. String name;
  6. double bal;
  7. account(int x, String y, int z)
  8. {
  9. no = x;
  10. name = y;
  11. type = z;
  12. bal = 500;
  13. }
  14. }
  15. class sav_acc extends account
  16. {
  17. DataInputStream ds=new DataInputStream(System.in);
  18. sav_acc(int x, String y, int z)
  19. {
  20. super(x,y,z);
  21. }
  22. void deposit1() throws IOException
  23. {
  24. System.out.println("Enter deposit amount");
  25. int dep = Integer.parseInt(ds.readLine());
  26. double ci = dep*(2.5/100);
  27. bal = bal + ci + dep;
  28. System.out.println("your balance is:" +bal);
  29. }
  30. void withdraw1() throws IOException
  31. {
  32. System.out.println("Enter withdraw amount");
  33. int wth = Integer.parseInt(ds.readLine());
  34. bal = bal - wth;
  35. if(bal<500)
  36. {
  37. System.out.println("Your balance is less than minimum amount");
  38. bal = bal + wth;
  39. }
  40. else
  41. System.out.println("withdraw successfully");
  42. System.out.println("Your balance is :"+bal);
  43. }
  44. }
  45. class cur_acc extends sav_acc
  46. {
  47. DataInputStream ds = new DataInputStream(System.in);
  48. cur_acc(int x, String y, int z)
  49. {
  50. super(x,y,z);
  51. }
  52. void deposit2() throws IOException
  53. {
  54. if(type==1)
  55. deposit1();
  56. else
  57. {
  58. System.out.println("enter deposit amount");
  59. int dep = Integer.parseInt(ds.readLine());
  60. bal = bal+dep;
  61. System.out.println("Your balance is:"+bal);
  62. }
  63. }
  64. void withdraw2() throws IOException
  65. {
  66. if(type==1)
  67. withdraw1();
  68. else
  69. {
  70. System.out.println("Enter the check no:");
  71. int ch = Integer.parseInt(ds.readLine());
  72. System.out.println("Enter withdraw amount");
  73. int wth = Integer.parseInt(ds.readLine());
  74. bal = bal - wth;
  75. if (bal <500)
  76. {
  77. System.out.println("Ur balance less than minimum");
  78. bal = bal + wth;
  79. }
  80. else
  81. {
  82. System.out.println("Withdraw successfully");
  83. System.out.println("Ur balance is:" +bal + "and your withdraw c");
  84. }
  85. }
  86. }
  87. void display2() throws IOException
  88. {
  89. String fac;
  90. String t;
  91. if(type==1)
  92. {
  93. fac = "False";
  94. t = "Saving";
  95. }
  96. else
  97. {
  98. fac="True";
  99. t="current";
  100. }
  101. System.out.println("=========================================");
  102. System.out.println("Bank Account ");
  103. System.out.println("=========================================");
  104. System.out.println("Account Number :" +no);
  105. System.out.println("Customer name :" +name);
  106. System.out.println("Account Type :" +t);
  107. System.out.println("Checque book :" +fac);
  108. System.out.println("Account Number :" +no);
  109. System.out.println("Current balance :" +bal);
  110. System.out.println("=========================================");
  111. System.out.println("=========================================");
  112. }
  113. }
  114. class BANK
  115. {
  116. public static void main(String ar[]) throws IOException
  117. {
  118. DataInputStream ds = new DataInputStream(System.in);
  119. System.out.println(" Bank Account");
  120. System.out.println("------------------------");
  121. System.out.println("Enter Account No. :");
  122. int n = Integer.parseInt(ds.readLine());
  123. System.out.println("Enter Customer Name :");
  124. String name = ds.readLine();
  125. System.out.println("1-> Saving Account");
  126. System.out.println("2-> Current Account");
  127. System.out.println("Select Account type");
  128. int t = Integer.parseInt(ds.readLine());
  129. cur_acc ob = new cur_acc(n, name, t);
  130. while(true)
  131. {
  132. System.out.println("1. Deposit");
  133. System.out.println("2. Withdarw");
  134. System.out.println("3. Balance");
  135. System.out.println("4. Exit");
  136. System.out.println("Enter ur choice");
  137. int ch = Integer.parseInt(ds.readLine());
  138. switch(ch)
  139. {
  140. case 1: ob.deposit2();
  141. break;
  142. case 2: ob.withdraw2();
  143. break;
  144. case 3: ob.display2();
  145. break;
  146. case 4: System.exit(0);
  147. break;
  148. default : System.out.println("Enter correct choice");
  149. break;
  150. }
  151. }
  152. }
  153. }