Maruf_Hasan

BankAccount

Sep 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. abstract class BankAccount
  4. {
  5. private String name;
  6. private String type;
  7. private String accountnum;
  8. private double balance;
  9. BankAccount(String nam,String actype,String num,double blnce)
  10. {
  11. name=nam;
  12. type=actype;
  13. num=accountnum;
  14. balance=blnce;
  15. }
  16. void depositamount(double amount)
  17. {
  18. balance+=amount;
  19. }
  20. void withdrawamount(double amount)
  21. {
  22. if(balance<amount)
  23. {
  24. System.out.println("Not Enough Balance");
  25. }
  26. else
  27. {
  28. System.out.println(+ amount +" is Withdrawn");
  29. balance-=amount;
  30. }
  31. }
  32. void Savings_deposit(int year)
  33. {
  34. double value=balance;
  35. for(int i=1;i<=year;i++)
  36. {
  37. value=value*(1.0+1/100);
  38. }
  39. balance=value;
  40. }
  41. void Fixed_Deposit(int year)
  42. {
  43. double value=balance;
  44. for(int i=1;i<=year;i++)
  45. {
  46. value=value*(1.0+1/100);
  47. }
  48. setbalance(value);
  49. }
  50. void displayNameAndBalance()
  51. {
  52. System.out.println("Name "+name);
  53. System.out.println("Account Type "+type);
  54. System.out.println("Account No "+accountnum);
  55. System.out.println("Balance "+balance);
  56. }
  57. double getbalance()
  58. {
  59. return balance;
  60. }
  61. void setbalance(double value)
  62. {
  63. balance=value;
  64. //System.out.println("AA "+balance);
  65. }
  66. String getName()
  67. {
  68. return name;
  69. }
  70. }
  71.  
  72. class SonaliBank extends BankAccount{
  73.  
  74. SonaliBank(String nam,String type,String accno,double blnce)
  75. {
  76. super(nam,type,accno,blnce);
  77. }
  78.  
  79. void Fixed_Deposit(int year)
  80. {
  81. double value=getbalance();
  82. for(int i=1;i<=year;i++)
  83. {
  84. value=value+(value*2.0/100);
  85. }
  86. setbalance(value);
  87. }
  88.  
  89. void displayNameAndBalance()
  90. {
  91. System.out.println("Sonali bank ");
  92. System.out.println("Name : " + getName());
  93. System.out.println("Balance : " + getbalance());
  94. }
  95. }
  96. class AgraniBank extends BankAccount{
  97.  
  98. AgraniBank(String nam,String type,String accno,double blnce)
  99. {
  100. super(nam,type,accno,blnce);
  101. }
  102.  
  103. void Fixed_Deposit(int year)
  104. {
  105. double value=getbalance();
  106. for(int i=1;i<=year;i++)
  107. {
  108. value=value+value*(3.0/100.0);
  109. }
  110. setbalance(value);
  111. }
  112.  
  113.  
  114. void displayNameAndBalance()
  115. {
  116. System.out.println("Agrani Bank ");
  117. System.out.println("Name : " + getName());
  118. System.out.println("Balance : " + getbalance());
  119. }
  120. }
  121.  
  122. class JanataBank extends BankAccount{
  123.  
  124. JanataBank(String nam,String type,String accno,double blnce)
  125. {
  126. super(nam,type,accno,blnce);
  127. }
  128.  
  129. void Fixed_Deposit(int year)
  130. {
  131. double value=getbalance();
  132. for(int i=1;i<=year;i++)
  133. {
  134. value+=value*(2.5/100.0);
  135. }
  136. setbalance(value);
  137. }
  138.  
  139.  
  140. void displayNameAndBalance()
  141. {
  142. System.out.println("Janata Bank ");
  143. System.out.println("Name : " + getName());
  144. System.out.println("Balance : " + getbalance());
  145. }
  146. }
  147.  
  148.  
  149.  
  150. public class BankingSystem {
  151.  
  152. public static void main(String[] args) {
  153. Scanner input = new Scanner(System.in);
  154. while(true)
  155. {
  156.  
  157. System.out.println("Enter the Bank ");
  158. System.out.println("1.Sonali Bank ");
  159. System.out.println("2.Agrani Bank ");
  160. System.out.println("Janata bank ");
  161. int choice;
  162. choice = input.nextInt();
  163. String nam,accno;
  164. int acctype;
  165. double balance=0.0;
  166. System.out.println("Enter the Name of Account");
  167. nam=input.next();
  168. System.out.println("Enter the type of Account");
  169. System.out.println("1.Fixed Deposit");
  170. System.out.println("2.Savings");
  171. acctype=input.nextInt();
  172. System.out.println("Enter the No of Account");
  173. accno=input.next();
  174. System.out.println("Enter balance");
  175. balance=input.nextDouble();
  176.  
  177. if(choice==1)
  178. {
  179. String type;
  180. if(acctype==1)
  181. {
  182. type="Fixed";
  183. }
  184. else
  185. type="Savings";
  186. BankAccount s;
  187. s=new SonaliBank(nam,type,accno,balance);
  188. System.out.println("Balance "+s.getbalance());
  189. System.out.println("Want to Depost or Withdraw");
  190. System.out.println("1.Deposit");
  191. System.out.println("2.Withdraw");
  192. int z=input.nextInt();
  193. if(z==1)
  194. {
  195. System.out.println("Enter the Time to to Deposit");
  196. int x;
  197. x=input.nextInt();
  198. if(acctype==1)
  199. {
  200. s.Fixed_Deposit(x);
  201. }
  202. else
  203. {
  204. s.Savings_deposit(x);
  205. }
  206. }
  207. else
  208. {
  209. int x;
  210. System.out.println("Enter the amount to withdraw");
  211. x=input.nextInt();
  212. s.withdrawamount(x);
  213. }
  214. s.displayNameAndBalance();
  215. }
  216. else if(choice==2)
  217. {
  218. String type;
  219. if(acctype==1)
  220. {
  221. type="Fixed";
  222. }
  223. else
  224. type="Savings";
  225. BankAccount ag=new AgraniBank(nam,type,accno,balance);
  226. System.out.println("Balance "+ag.getbalance());
  227. System.out.println("Want to Depost or Withdraw");
  228. System.out.println("1.Deposit");
  229. System.out.println("2.Withdraw");
  230. int z=input.nextInt();
  231. if(z==1)
  232. {
  233. System.out.println("Enter the Time to to Deposit");
  234. int x;
  235. x=input.nextInt();
  236. if(acctype==1)
  237. {
  238. ag.Fixed_Deposit(x);
  239. }
  240. else
  241. {
  242. ag.Savings_deposit(x);
  243. }
  244. }
  245. else
  246. {
  247. int x;
  248. System.out.println("Enter the amount to withdraw");
  249. x=input.nextInt();
  250. ag.withdrawamount(x);
  251. }
  252. ag.displayNameAndBalance();
  253. }
  254. else if(choice==3)
  255. {
  256. String type;
  257. if(acctype==1)
  258. {
  259. type="Fixed";
  260. }
  261. else
  262. type="Savings";
  263. BankAccount jb=new JanataBank(nam,type,accno,balance);
  264. System.out.println("Balance "+jb.getbalance());
  265. System.out.println("Want to Depost or Withdraw");
  266. System.out.println("1.Deposit");
  267. System.out.println("2.Withdraw");
  268. int z=input.nextInt();
  269. if(z==1)
  270. {
  271. System.out.println("Enter the Time to to Deposit");
  272. int x;
  273. x=input.nextInt();
  274. if(acctype==1)
  275. {
  276. jb.Fixed_Deposit(x);
  277. // System.out.println("X "+value);
  278. }
  279. else
  280. {
  281. jb.Savings_deposit(x);
  282. }
  283. }
  284. else
  285. {
  286. int x;
  287. System.out.println("Enter the amount to withdraw");
  288. x=input.nextInt();
  289. jb.withdrawamount(x);
  290. }
  291. jb.displayNameAndBalance();
  292. }
  293. System.out.println("DO U want to check again");
  294. System.out.println("1.YES");
  295. System.out.println("2.No");
  296. int check;
  297. check=input.nextInt();
  298. if(check==2)
  299. {
  300. break;
  301. }
  302. }
  303. }
  304. }
Add Comment
Please, Sign In to add comment