-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank Account Main
73 lines (63 loc) · 2.47 KB
/
Bank Account Main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.ArrayList;
import java.util.Collections;
public class BankAccountMain {
public static void main(String[] args) {
// Creating Bank Accounts
BankAccount firstAccount = new BankAccount("Fred Flintstone", 345.67);
System.out.println(firstAccount);
BankAccount secondAccount = new BankAccount("Betty Rubble", 1456.70);
System.out.println(secondAccount);
// Update the balances
firstAccount.deposit(73.00);
secondAccount.withdraw(123.45);
System.out.println(firstAccount);
System.out.println(secondAccount);
// Setting the interest rates
BankAccount.setInterestRate(2.4);
firstAccount.addInterest();
System.out.println(firstAccount);
// Checking to see if the balances ought to be waived
if (firstAccount.isBalanceOver(500))
System.out.println("Your bank fees will be waved");
else
System.out.println("Your bank fee is $3.00");
if (secondAccount.isBalanceOver(500))
System.out.println("Your bank fees will be waved");
else
System.out.println("Your bank fee is $3.00");
// Array
ArrayList<BankAccount> accountList = new ArrayList<BankAccount>();
accountList.add(new BankAccount("Ace Ventura", 632.25));
accountList.add(new BankAccount("Liz Arden", 8885.78));
accountList.add(new BankAccount("Tim Horton", 1345.67));
accountList.add(new BankAccount("Clara Hughes", 895.24));
accountList.add(new BankAccount("Jack Bauer", 217.12));
accountList.add(new BankAccount("Lara Croft", 4317.39));
for (BankAccount nextAccount : accountList)
System.out.println(nextAccount);
System.out.println("");
//If balance is over 1000, add 25 dollars
for (BankAccount nextAccount : accountList) {
if (nextAccount.isBalanceOver(1000)) {
nextAccount.deposit(25);
}
System.out.println(nextAccount);
}
//Linear Search using Index Of
// BankAccount target = new BankAccount("Tim Horton", 1345.67);
// int index = accountList.indexOf (target);
// System.out.printf("Index of %s is: %d%n", target, index);
Collections.sort(accountList);
BankAccount target = new BankAccount("Kim Weston", 1345.67);
int index = Collections.binarySearch(accountList, target);
//index stored is (-)insertion index-1 (actual place is 3)
System.out.printf("Index of %s is: %d%n", target, index);
//Add the account to the proper place within the sort
accountList.add(-index-1, target);
for (BankAccount nextAccount: accountList)
{
System.out.println(nextAccount);
}
Collections.sort(accountList, BankAccount.BALANCE_ORDER);
}
}