Guest User

Untitled

a guest
Jun 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. package day2;
  2.  
  3.  
  4.  
  5. import java.util.Random;
  6. import java.util.Scanner;
  7.  
  8. public class Q3 {
  9.  
  10. public static void main(String[] args)
  11. {
  12. Scanner scanner=new Scanner(System.in);
  13. System.out.println("enter the account name");
  14. String name=scanner.next();
  15.  
  16. System.out.println("what type of account do u open press 1 for saving account and press 2 for cuurent account");
  17. int n=scanner.nextInt();
  18.  
  19. System.out.println("enter initial balance");
  20. //System.out.println(5+10);
  21. double balance=scanner.nextDouble();
  22.  
  23. double bal=balance+ 5.0/100*balance;
  24. //System.out.println(bal);
  25.  
  26. if(n==1){
  27. SavingAccount savingaccount=new SavingAccount(name, bal);
  28. //savingaccount.setAccountBalance();
  29.  
  30. System.out.println("enter 1 for deposit money, 2 for withdraw money, 3 for display the account balance");
  31. int c=scanner.nextInt();
  32. switch(c){
  33. case 1:
  34. System.out.println("enter money to deposit");
  35. double deposit=scanner.nextDouble();
  36.  
  37. savingaccount.deposit(deposit);
  38. savingaccount.display();
  39. break;
  40. case 2:
  41. System.out.println("enter money to withdraw");
  42. double withdraw=scanner.nextDouble();
  43. savingaccount.withdraw(withdraw);
  44. savingaccount.display();
  45. break;
  46. case 3:
  47. savingaccount.display();
  48. break;
  49. }
  50. }
  51. if(n==2){
  52. CurrentAccount currentaccount=new CurrentAccount(name,balance);
  53. System.out.println("enter 1 for deposit money, 2 for withdraw money, 3 for display the account balance");
  54. int c1=scanner.nextInt();
  55. switch(c1){
  56. case 1:
  57. System.out.println("enter money to deposit");
  58. double deposit=scanner.nextDouble();
  59.  
  60. currentaccount.deposit(deposit);
  61. currentaccount.display();
  62. break;
  63. case 2:
  64. System.out.println("enter money to withdraw");
  65. double withdraw=scanner.nextDouble();
  66. currentaccount.withdraw(withdraw);
  67. currentaccount.display();
  68. break;
  69. case 3:
  70. currentaccount.display();
  71. break;
  72. }
  73. //account.display();
  74. scanner.close();
  75. }
  76. }
  77. }
  78. class SavingAccount extends Account {
  79. //private int mainterest = 5;
  80. //private double maximumWithdrawAmount;
  81.  
  82. public SavingAccount(String accountHolderName, double accountBalance)
  83. {
  84. super(accountHolderName, accountBalance,"");
  85. }
  86.  
  87.  
  88. void getBalance() {
  89.  
  90. }
  91.  
  92. void deposit(double deposit) {
  93. super.setAccountBalance((super.getAccountBalance() + deposit));
  94.  
  95. }
  96.  
  97. void withdraw(double deposit) {
  98. if (super.getAccountBalance() > deposit) {
  99. super.setAccountBalance((super.getAccountBalance() - deposit));
  100. } else {
  101. System.out
  102. .println("balance can not be exceed than account balance");
  103. }
  104.  
  105. }
  106.  
  107. }
  108. class CurrentAccount extends Account {
  109.  
  110. int tradeLicenseNumber;
  111.  
  112.  
  113. public CurrentAccount(String accountHolderName, double accountBalance)
  114. {
  115. super(accountHolderName, accountBalance,"");
  116. }
  117. void deposit(double deposit) {
  118. super.setAccountBalance((super.getAccountBalance() + deposit));
  119.  
  120. }
  121.  
  122. void withdraw(double deposit) {
  123. if (super.getAccountBalance() > deposit) {
  124. super.setAccountBalance((super.getAccountBalance() - deposit));
  125. } else {
  126. System.out
  127. .println("balance can not be exceed than account balance");
  128. }
  129. }
  130. }
  131. class Account {
  132. // private string accountNumber;
  133. private String accountHolderName;
  134. private double accountBalance;
  135. private String accountNumber;
  136. public Account()
  137. {
  138. }
  139. public Account(String accountHolderName, double accountBalance,String accountNumber) {
  140. Random rand = new Random();
  141. this.accountNumber = accountNumber + rand.nextInt(10)
  142. + rand.nextInt(10) + rand.nextInt(10) + rand.nextInt(10)
  143. + rand.nextInt(10);
  144.  
  145. this.accountHolderName = accountHolderName;
  146. this.accountBalance = accountBalance;
  147. }
  148.  
  149. public String getAccountHolderName() {
  150. return accountHolderName;
  151. }
  152.  
  153. public double getAccountBalance() {
  154. return accountBalance;
  155. }
  156.  
  157. public String getAccountNumber() {
  158. return accountNumber;
  159. }
  160.  
  161. public void setAccountBalance(double accountBalance) {
  162. this.accountBalance = accountBalance;
  163. }
  164.  
  165. void display() {
  166. System.out.println(this.getAccountHolderName());
  167. System.out.println(this.getAccountNumber());
  168. System.out.println(this.getAccountBalance());
  169.  
  170. }
  171.  
  172. }
Add Comment
Please, Sign In to add comment