Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Tester;
- import java.time.LocalDate;
- import java.util.Random;
- import BankAccounts.Account;
- import BankAccounts.LoanableAccount;
- import BankPkg.AccountType;
- import BankPkg.Bank;
- public class Tester {
- static Random rnd = new Random();
- static AccountType[] typesArray = AccountType.values();
- static Bank myBank = new Bank();
- public static void CreateAccounts(Bank aBank, int n) {
- for (int i = 1; i <= n; i += 1) {
- int personId;
- boolean clientCreated = false;
- do {
- System.out.println("trying to create a new account!");
- String personName = "Name" + (char) (60 + rnd.nextInt(35));
- personId = 10000000 + rnd.nextInt(900000000);
- LocalDate birthDate = LocalDate.of(1988 + rnd.nextInt(18),
- 1 + rnd.nextInt(12), 1 + rnd.nextInt(28));
- clientCreated = aBank
- .addClient(personName, personId, birthDate);
- } while (!clientCreated);
- int accountNo;
- AccountType type;
- do {
- type = typesArray[rnd.nextInt(typesArray.length)];
- accountNo = aBank.addAccount(personId, type);
- } while (accountNo == -1);
- System.out.printf("new account created (%d of %d)\n", i, n);
- }
- }
- public static void printStat() {
- System.out.println("Number of accounts from each type:");
- for (AccountType item : typesArray) {
- System.out.printf("%3d of type %s\n",
- Account.getTypeAccountsCounter(item), item.name());
- }
- }
- public static void printAccountsList(String title, Account[] accountList) {
- System.out.println(title);
- for (Account item : accountList) {
- System.out.println(item);
- }
- }
- public static void main(String[] args) {
- CreateAccounts(myBank, 10);
- printStat();
- Account[] studentsAccounts = myBank
- .getAccountsByType(AccountType.student);
- printAccountsList("accounts of type student", studentsAccounts);
- for (Account item : myBank.getAccounts()) {
- myBank.withdraw(item.getAccountId(), 4000);
- if (item instanceof LoanableAccount) {
- myBank.giveLoan(item.getAccountId(), 18000, 36);
- }
- }
- printAccountsList("all Bank account", myBank.getAccounts());
- Account[] invalid2020 = myBank.getInvalidAgeAccounts(LocalDate.of(2018,
- 12, 31));
- printAccountsList("Invalid Accounts at 1/1/2020", invalid2020);
- System.out.println(myBank.getClients("fsdfs"));
- for (Account item : myBank.getAccounts()) {
- if (item instanceof LoanableAccount) {
- myBank.loanPaymentReturn(item.getAccountId());
- }
- }
- printAccountsList("all Bank account", myBank.getAccounts());
- }
- }
Add Comment
Please, Sign In to add comment