· 4 years ago · Jan 24, 2021, 07:36 PM
1package accounts;
2
3public abstract class Account {
4 protected int id;
5 protected double balance;
6 protected String name;
7 protected int accountNumber;
8 protected double maximumOverdraw;
9 protected double commissionPercentage;
10
11 public Account(int id,
12 String name,
13 int accountNumber,
14 double maximumOverdraw,
15 double commissionPercentage) {
16 this.id = id;
17 this.name = name;
18 this.accountNumber = accountNumber;
19 this.maximumOverdraw = maximumOverdraw;
20 this.commissionPercentage = commissionPercentage;
21 }
22
23 public boolean withdrawBalance(double amount) {
24 boolean result = false;
25 if (amount > 0) {
26 double tax = (amount / 100.00) * commissionPercentage;
27 double newBalance = this.balance - amount - tax;
28 if (newBalance < (this.maximumOverdraw * -1)) {
29 System.out.println("Failed your maximal overdraw is - " + this.maximumOverdraw);
30 } else {
31 this.balance = newBalance;
32 System.out.println("The operation was successful");
33 result = true;
34 }
35 } else {
36 System.out.println("The amount that was provided was negative");
37 }
38 return result;
39 }
40
41 public boolean addToBalance(double amount) {
42 boolean result = false;
43 if (amount < 0) {
44 System.out.println("The amount that was provided was negative");
45 } else {
46 double tax = (amount / 100.00) * commissionPercentage;
47 this.balance = this.balance + amount - tax;
48 System.out.println("The operation was successful");
49 result = true;
50 }
51 return result;
52 }
53
54 public double getBalance() {
55 return this.balance;
56 }
57
58 public int getAccountNumber() {
59 return this.accountNumber;
60 }
61}
62====================================================================================================================================
63package accounts;
64
65import util.CommissionPercentages;
66
67public class BusinessAccount extends LoanTakingAccount {
68 private String secretKey;
69
70 public BusinessAccount(int id, String name, int accountNumber, double maximumOverdraw) {
71 super(id, name, accountNumber, maximumOverdraw, CommissionPercentages.BUSINESS_COMMISSION_PERCENTAGE);
72 }
73
74 public String getSecretKey() {
75 return secretKey;
76 }
77
78 public void setSecretKey(String secretKey) {
79 this.secretKey = secretKey;
80 }
81
82 public void changeCommissionPercentage(double newValue) {
83 if (newValue < 0) {
84 System.out.println("The value was negative");
85 } else {
86 this.commissionPercentage = newValue;
87 }
88 }
89
90
91}
92=========================================================================================================================
93package accounts;
94
95import util.CommissionPercentages;
96
97public class StudentAccount extends LoanTakingAccount {
98 public StudentAccount(int id, String name, int accountNumber) {
99 super(id, name, accountNumber, 0, CommissionPercentages.STUDENT_COMMISSION_PERCENTAGE);
100 }
101
102}
103==================================================================================================
104package accounts;
105
106public class LoanTakingAccount extends Account {
107 public LoanTakingAccount(int id, String name, int accountNumber, double maximumOverdraw, double commissionPercentage) {
108 super(id, name, accountNumber, maximumOverdraw, commissionPercentage);
109 }
110 public boolean takeALoan(double amount) {
111 boolean result = false;
112 if (amount <0) {
113 System.out.println("The amount provided is negative");
114 } else {
115 result = true;
116 }
117 return result;
118 }
119}
120================================================================================================
121package accounts;
122
123import util.CommissionPercentages;
124
125public class RegularAccount extends LoanTakingAccount {
126 public RegularAccount(int id, String name, int accountNumber, double maximumOverdraw) {
127 super(id, name, accountNumber, maximumOverdraw, CommissionPercentages.REGULAR_COMMISSION_PERCENTAGE);
128 }
129}
130======================================================================================================
131package accounts;
132
133import util.CommissionPercentages;
134
135public class YoungAccount extends Account {
136 public YoungAccount(int id, String name, int accountNumber) {
137 super(id, name, accountNumber, 0, CommissionPercentages.YOUNG_COMMISSION_PERCENTAGE);
138 }
139}
140============================================================================================================
141import accounts.BusinessAccount;
142import accounts.RegularAccount;
143import accounts.StudentAccount;
144import accounts.YoungAccount;
145import bank.Bank;
146
147public class Program {
148 public static void main(String[] args) {
149 Bank bank = new Bank(4);
150 StudentAccount studentAccount = bank.openStudentAccount(325478516, "Gogo");
151 RegularAccount regularAccount = bank.openRegularAccount(354653156, "Lolo", 10000);
152 BusinessAccount businessAccount =bank.openBusinessAccount(654785478,"Momo",5000);
153 YoungAccount youngAccount =bank.openYoungAccount(254784152,"Koko");
154
155 bank.printAllBankAccountsWithNegativeBalance();
156 regularAccount.withdrawBalance(7000);
157 bank.printAllBankAccountsWithNegativeBalance();
158 }
159}
160