Guest User

Untitled

a guest
Jun 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. package com.batch5.account;
  2. import com.batch5.randomgenerator.*;
  3.  
  4. public class Account {
  5. private String memberName;
  6. private String accountNumber;
  7. private double accountBalance;
  8. RandomNumber random= new RandomNumber();
  9.  
  10.  
  11. Account(){}
  12.  
  13. Account(String memberName, double accountBalance)
  14. {
  15. this.memberName=memberName;
  16. this.accountBalance=accountBalance;
  17. accountNumber=random.RandomGenerator();
  18.  
  19. }
  20.  
  21.  
  22.  
  23. public String getMemberName() {
  24. return memberName;
  25. }
  26.  
  27. public String getAccountNumber() {
  28. return accountNumber;
  29. }
  30.  
  31. public double getAccountBalance() {
  32. return accountBalance;
  33. }
  34.  
  35. public void setMemberName(String memberName) {
  36. this.memberName = memberName;
  37. }
  38.  
  39. public void setAccountBalance(double accountBalance) {
  40. this.accountBalance = accountBalance;
  41. }
  42. //---------------------------------------------------------------------------------------//
  43. public double withdraw(double amount)
  44. {
  45. accountBalance-=amount;
  46. return accountBalance;
  47. }
  48.  
  49. public double deposit()
  50. {
  51. return accountBalance;
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. public void accountInfo()
  60. {
  61. System.out.println("Account number is="+ accountNumber);
  62. }
  63. }
  64. -----------------------------------------------------------------
  65.  
  66. package com.batch5.account;
  67. import com.batch5.randomgenerator.*;
  68.  
  69. public class Account {
  70. private String memberName;
  71. private String accountNumber;
  72. private double accountBalance;
  73. RandomNumber random= new RandomNumber();
  74.  
  75.  
  76. Account(){}
  77.  
  78. Account(String memberName, double accountBalance)
  79. {
  80. this.memberName=memberName;
  81. this.accountBalance=accountBalance;
  82. accountNumber=random.RandomGenerator();
  83.  
  84. }
  85.  
  86.  
  87.  
  88. public String getMemberName() {
  89. return memberName;
  90. }
  91.  
  92. public String getAccountNumber() {
  93. return accountNumber;
  94. }
  95.  
  96. public double getAccountBalance() {
  97. return accountBalance;
  98. }
  99.  
  100. public void setMemberName(String memberName) {
  101. this.memberName = memberName;
  102. }
  103.  
  104. public void setAccountBalance(double accountBalance) {
  105. this.accountBalance = accountBalance;
  106. }
  107. //---------------------------------------------------------------------------------------//
  108. package com.batch5.account;
  109.  
  110. import java.util.Scanner;
  111.  
  112.  
  113. public class Bank {
  114. Bank(){}
  115.  
  116. public static void main(String args[])
  117. {
  118. Scanner in= new Scanner(System.in);
  119. String accountHolderName;
  120. double initialBalance;
  121. String choice2;
  122. System.out.println("Welcome to Nucleus batch 5 banking system.......");
  123. System.out.println("Do you want to open an account ?(Y/N)");
  124. String choice1=in.next();
  125. if(choice1.equals("Y"))
  126. {
  127. System.out.println("Enter account holder name:");
  128. accountHolderName=in.next();
  129. System.out.println("Enter initial balance");
  130. initialBalance=in.nextDouble();
  131. System.out.println("What type of account you want to create(Savings(S)/Current(C):");
  132. choice2=in.next();
  133.  
  134. if(choice2.equals("S"))
  135. {
  136. Account account= new Account(accountHolderName,initialBalance);
  137. Account savingAccount=new SavingAccount(10000.00,500.00);
  138. account.accountInfo();
  139.  
  140. System.out.println("Press [1] to DEPOSIT , Press [2] to WITHDRAW , " +
  141. "Press [3] to DISPLAY BALANCE , Press [0] to EXIT....)");
  142. int choice3=in.nextInt();
  143. switch(choice3)
  144. {
  145. case 1:
  146. System.out.println("Enter amount to be deposited");
  147. double addAmount=in.nextDouble();
  148. System.out.println("Deposit add with interest ! Do you want to check balance ?(y/n)");
  149. String internalChoice1=in.next();
  150.  
  151. if(internalChoice1.equals("Y"))
  152. System.out.println(savingAccount.getbalance());
  153. else
  154. savingAccount.getbalance();
  155.  
  156. }
  157.  
  158.  
  159. }
  160.  
  161.  
  162. }
  163. }
  164.  
  165. }
  166.  
  167. --------------------------------------------------------------------
  168.  
  169. package com.batch5.account;
  170.  
  171. public class CurrentAccount extends Account {
  172. String tradeLicenseNumber;
  173. Account account = new Account();
  174.  
  175. public CurrentAccount() {
  176. // TODO Auto-generated constructor stub
  177. }
  178.  
  179. public CurrentAccount(String tradeLicenseNumber)
  180. {
  181. this.tradeLicenseNumber=tradeLicenseNumber;
  182. }
  183.  
  184. public String getTradeLicenseNumber() {
  185. return tradeLicenseNumber;
  186. }
  187.  
  188. public void setTradeLicenseNumber(String tradeLicenseNumber) {
  189. this.tradeLicenseNumber = tradeLicenseNumber;
  190. }
  191. //---------------------------------------------------------------------------------------//
  192.  
  193.  
  194. public double getbalance()
  195. {
  196. return account.getAccountBalance();
  197. }
  198.  
  199. @Override
  200. public double withdraw(double amount)
  201. {
  202. if(account.getAccountBalance()>account.getAccountBalance())
  203. {
  204. account.setAccountBalance(account.getAccountBalance()-amount);
  205. return account.getAccountBalance();
  206. }
  207.  
  208. else
  209. {
  210. System.out.println("More than balance available amount entered");
  211. return 0;
  212. }
  213.  
  214. }
  215.  
  216.  
  217.  
  218. }
  219. ---------------------------------------------------
  220.  
  221. package com.batch5.account;
  222.  
  223. public class SavingAccount extends Account {
  224. private double interest,withdraw_limit,minBalance;
  225. //Account account= new Account();
  226.  
  227. SavingAccount()
  228. {
  229. super();
  230. }
  231.  
  232. SavingAccount(double withdraw_limit,double minBalance)
  233. {
  234. //super();
  235. interest=0.05;
  236. this.withdraw_limit=withdraw_limit;
  237. this.minBalance=minBalance;
  238. }
  239.  
  240. public double getInterest() {
  241. return interest;
  242. }
  243.  
  244. public double getWithdraw_limit() {
  245. return withdraw_limit;
  246. }
  247.  
  248. public void setInterest(double interest) {
  249. this.interest = interest;
  250. }
  251.  
  252. public void setWithdraw_limit(double withdraw_limit) {
  253. this.withdraw_limit = withdraw_limit;
  254. }
  255.  
  256.  
  257.  
  258. public double getMinBalance() {
  259. return minBalance;
  260. }
  261.  
  262. public void setMinBalance(double minBalance) {
  263. this.minBalance = minBalance;
  264. }
  265. //---------------------------------------------------------------------------------------//
  266. /*public double savingInfo()
  267. {
  268.  
  269. }*/
  270. public double getbalance()
  271. {
  272. return account.getAccountBalance()*interest+account.getAccountBalance();
  273. }
  274.  
  275. @Override
  276. public double withdraw(double withdraw_amount)
  277. {
  278. if((withdraw_amount>withdraw_limit))
  279. {
  280. System.out.println("Overflow");
  281. return 0;
  282. }
  283. else
  284. {
  285. if((account.getalance()-withdraw_amount)<minBalance)
  286. {
  287. System.out.println("underflow !!");
  288. return 0;
  289. }
  290. else
  291. return account.getAccountBalance()-withdraw_amount;
  292. }
  293. }
  294.  
  295.  
  296. }
  297. --------------------------------------------------------------------
  298.  
  299. package com.batch5.randomgenerator;
  300.  
  301. import java.util.Random;
  302.  
  303. public class RandomNumber {
  304. String number;
  305. //RandomNumber(){}
  306.  
  307. public String RandomGenerator()
  308. {
  309. Random rand = new Random();
  310. number ="" + rand.nextInt(10) + rand.nextInt(10)+ rand.nextInt(10)+
  311. rand.nextInt(10)+ rand.nextInt(10);
  312.  
  313. return number;
  314. }
  315.  
  316.  
  317. }
Add Comment
Please, Sign In to add comment