Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mindaugas.bankmodelingapp;
- import java.util.ArrayList;
- import java.util.List;
- public class App {
- public static void main(String args[]) {
- ArrayList<Customer> customers = new ArrayList<>();
- customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
- add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
- customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
- add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
- customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
- add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
- customers.add(new Customer("Mindaugas", 10008, new ArrayList<Account>() {{
- add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }} ));
- Bank bank = new Bank("Swedbank", "HABALT22", customers);
- // ... interacting with a single customer
- Customer customerMindaugas = new Customer("Mindaugas", 10008, new ArrayList<Account>()
- {{ add(new SalaryAccount("Mano geras acc", 10008, "Darbas")); }}
- );
- customerMindaugas.getAccounts().get(0).deposit(100);
- System.out.println("Mindaugas has " + customerMindaugas.getAccounts().get(0).getAmount() + "€, in his account!");
- }
- }
- class Bank {
- private String name;
- private String swift;
- List<Customer> customers;
- public Bank(String name, String swift, List<Customer> customers) {
- this.name = name;
- this.swift = swift;
- this.customers = customers;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSwift() {
- return swift;
- }
- public void setSwift(String swift) {
- this.swift = swift;
- }
- public List<Customer> getCustomers() {
- return customers;
- }
- public void setCustomers(List<Customer> customers) {
- this.customers = customers;
- }
- }
- class Customer {
- private String name;
- private int customerId;
- private List<Account> accounts;
- public Customer(String name, int customerId, List<Account> accounts) {
- this.name = name;
- this.customerId = customerId;
- this.accounts = accounts;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getCustomerId() {
- return customerId;
- }
- public void setCustomerId(int customerId) {
- this.customerId = customerId;
- }
- public List<Account> getAccounts() {
- return accounts;
- }
- public void setAccounts(List<Account> accounts) {
- this.accounts = accounts;
- }
- }
- abstract class Account {
- private String name;
- private int customerId;
- private double amount;
- public Account(String name, int customerId) {
- this.name = name;
- this.customerId = customerId;
- }
- public void deposit(double amount){
- this.amount += amount;
- }
- public void withdraw(double amount){
- this.amount -= amount;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getCustomerId() {
- return customerId;
- }
- public void setCustomerId(int customerId) {
- this.customerId = customerId;
- }
- public double getAmount() {
- return amount;
- }
- public void setAmount(double amount) {
- this.amount = amount;
- }
- }
- class SalaryAccount extends Account {
- private String employersName; // darbovietės pavadinimas
- public SalaryAccount(String name, int customerId, String employersName) {
- super(name, customerId);
- this.employersName = employersName;
- }
- public String getEmployersName() {
- return employersName;
- }
- public void setEmployersName(String employersName) {
- this.employersName = employersName;
- }
- }
- class InvestmentAccount extends Account {
- private double interestRate;
- public InvestmentAccount(String name, int customerId, double interestRate) {
- super(name, customerId);
- this.interestRate = interestRate;
- }
- public double getInterestRate() {
- return interestRate;
- }
- public void setInterestRate(double interestRate) {
- this.interestRate = interestRate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement