sunspeak

Untitled

Oct 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.String;
  3.  
  4.  
  5. public class Main
  6. {
  7. public static void main(String[] args) {
  8. Scanner scan = new Scanner(System.in);
  9. String a = scan.next();
  10.  
  11. while (!a.equals("End")) {
  12.  
  13. if (a.equals("Create")) {
  14.  
  15. BankAccount.accounts();
  16.  
  17. }
  18. else if(a.equals("Deposit"))
  19. {
  20. int id = scan.nextInt();
  21. double amount = scan.nextDouble();
  22. BankAccount.deposit(id, amount);
  23. }
  24. else if(a. equals("SetInterest"))
  25. {
  26. double setInterest = scan.nextDouble();
  27. BankAccount.setInterestRate(setInterest);
  28. }
  29. else if(a. equals("GetInterest"))
  30. {
  31. int id = scan.nextInt();
  32. int year = scan.nextInt();
  33. if (BankAccount.getInterest(id,year) != -1)
  34. {
  35. System.out.println(BankAccount.getInterest(id, year));
  36. }
  37.  
  38.  
  39. }
  40. a = scan.next();
  41. }
  42.  
  43.  
  44. }
  45. }
  46.  
  47.  
  48.  
  49. import java.util.ArrayList;
  50.  
  51.  
  52. public class BankAccount
  53. {
  54. private final static double DEFAULT_INTEREST_RATE = 0.02;
  55. private static int id;
  56. private double balance;
  57. private static double interestRate = DEFAULT_INTEREST_RATE;
  58. private static int bankAccount = 1;
  59. private static ArrayList BankAccounts = new ArrayList();
  60.  
  61. BankAccount()
  62. {
  63. this.id = bankAccount++;
  64. this.balance = balance;
  65.  
  66.  
  67. }
  68. BankAccount(double amount)
  69. {
  70. this.id = id;
  71. this.balance += amount;
  72.  
  73.  
  74. }
  75. static void accounts()
  76. {
  77.  
  78. BankAccounts.add(new BankAccount());
  79. System.out.println("ID"+id);
  80. }
  81. static void setInterestRate(double interestRate)
  82. {
  83. BankAccount.interestRate = interestRate;
  84. }
  85. static void deposit(int id, double amount)
  86. {
  87.  
  88. if (id > BankAccounts.size())
  89. {
  90. System.out.println("Account does not exist");
  91. return;
  92. }
  93. id--;
  94. BankAccounts.set(id, new BankAccount(amount));
  95. System.out.println("Deposit "+ amount + " to ID" + ++id);
  96. }
  97. static double getInterest ( int id, int years)
  98. {
  99.  
  100. if (id > BankAccounts.size())
  101. {
  102. System.out.println("Account does not exist");
  103. return -1;
  104. }
  105. id--;
  106. BankAccount temp = (BankAccount) BankAccounts.get(id);
  107. return BankAccount.interestRate * years * temp.balance;
  108. }
  109.  
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment