Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. package com.mindaugas.bankmodelingapp;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class App {
  7. public static void main(String args[]) {
  8. ArrayList<Customer> customers = new ArrayList<>();
  9. customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
  10. add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
  11. customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
  12. add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
  13. customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
  14. add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
  15. customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
  16. add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
  17.  
  18. Bank bank = new Bank("Swedbank", "HABALT22", customers);
  19.  
  20.  
  21. // ... interacting with a single customer
  22. Customer customerMindaugas = new Customer("Mindaugas", 10008, new ArrayList<Account>()
  23. {{ add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }}
  24. );
  25.  
  26. customerMindaugas.getAccounts().get(0).deposit(100);
  27. System.out.println("Mindaugas has " + customerMindaugas.getAccounts().get(0).getAmount() + "€, in his account!");
  28.  
  29. }
  30. }
  31.  
  32. class Bank {
  33. private String name;
  34. private String swift;
  35. List<Customer> customers;
  36.  
  37. public Bank(String name, String swift, List<Customer> customers) {
  38. this.name = name;
  39. this.swift = swift;
  40. this.customers = customers;
  41. }
  42.  
  43. public String getName() {
  44. return name;
  45. }
  46.  
  47. public void setName(String name) {
  48. this.name = name;
  49. }
  50.  
  51. public String getSwift() {
  52. return swift;
  53. }
  54.  
  55. public void setSwift(String swift) {
  56. this.swift = swift;
  57. }
  58.  
  59. public List<Customer> getCustomers() {
  60. return customers;
  61. }
  62.  
  63. public void setCustomers(List<Customer> customers) {
  64. this.customers = customers;
  65. }
  66.  
  67.  
  68. }
  69.  
  70. class Customer {
  71. private String name;
  72. private int customerId;
  73. private List<Account> accounts;
  74.  
  75. public Customer(String name, int customerId, List<Account> accounts) {
  76. this.name = name;
  77. this.customerId = customerId;
  78. this.accounts = accounts;
  79. }
  80.  
  81. public String getName() {
  82. return name;
  83. }
  84.  
  85. public void setName(String name) {
  86. this.name = name;
  87. }
  88.  
  89. public int getCustomerId() {
  90. return customerId;
  91. }
  92.  
  93. public void setCustomerId(int customerId) {
  94. this.customerId = customerId;
  95. }
  96.  
  97. public List<Account> getAccounts() {
  98. return accounts;
  99. }
  100.  
  101. public void setAccounts(List<Account> accounts) {
  102. this.accounts = accounts;
  103. }
  104. }
  105.  
  106. abstract class Account {
  107. private String name;
  108. private int customerId;
  109. private double amount;
  110.  
  111. public Account(String name, int customerId) {
  112. this.name = name;
  113. this.customerId = customerId;
  114. }
  115.  
  116. public void deposit(double amount){
  117. this.amount += amount;
  118. }
  119.  
  120. public void withdraw(double amount){
  121. this.amount -= amount;
  122. }
  123.  
  124. public String getName() {
  125. return name;
  126. }
  127.  
  128. public void setName(String name) {
  129. this.name = name;
  130. }
  131.  
  132. public int getCustomerId() {
  133. return customerId;
  134. }
  135.  
  136. public void setCustomerId(int customerId) {
  137. this.customerId = customerId;
  138. }
  139.  
  140. public double getAmount() {
  141. return amount;
  142. }
  143.  
  144. public void setAmount(double amount) {
  145. this.amount = amount;
  146. }
  147. }
  148.  
  149. class SalaryAccount extends Account {
  150. private String employersName; // darbovietės pavadinimas
  151.  
  152. public SalaryAccount(String name, int customerId, String employersName) {
  153. super(name, customerId);
  154. this.employersName = employersName;
  155. }
  156.  
  157. public String getEmployersName() {
  158. return employersName;
  159. }
  160.  
  161. public void setEmployersName(String employersName) {
  162. this.employersName = employersName;
  163. }
  164. }
  165.  
  166. class InvestmentAccount extends Account {
  167. private double interestRate;
  168.  
  169. public InvestmentAccount(String name, int customerId, double interestRate) {
  170. super(name, customerId);
  171. this.interestRate = interestRate;
  172. }
  173.  
  174. public double getInterestRate() {
  175. return interestRate;
  176. }
  177.  
  178. public void setInterestRate(double interestRate) {
  179. this.interestRate = interestRate;
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement