· 4 years ago · Jan 24, 2021, 07:34 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=======================================================================================================================================package accounts;
63
64import util.CommissionPercentages;
65
66public class BusinessAccount extends LoanTakingAccount {
67 private String secretKey;
68
69 public BusinessAccount(int id, String name, int accountNumber, double maximumOverdraw) {
70 super(id, name, accountNumber, maximumOverdraw, CommissionPercentages.BUSINESS_COMMISSION_PERCENTAGE);
71 }
72
73 public String getSecretKey() {
74 return secretKey;
75 }
76
77 public void setSecretKey(String secretKey) {
78 this.secretKey = secretKey;
79 }
80
81 public void changeCommissionPercentage(double newValue) {
82 if (newValue < 0) {
83 System.out.println("The value was negative");
84 } else {
85 this.commissionPercentage = newValue;
86 }
87 }
88
89
90}
91=======================================================================================================package accounts;
92
93import util.CommissionPercentages;
94
95public class StudentAccount extends LoanTakingAccount {
96 public StudentAccount(int id, String name, int accountNumber) {
97 super(id, name, accountNumber, 0, CommissionPercentages.STUDENT_COMMISSION_PERCENTAGE);
98 }
99
100}
101=========================================================================================================================
102package accounts;
103
104public class LoanTakingAccount extends Account {
105 public LoanTakingAccount(int id, String name, int accountNumber, double maximumOverdraw, double commissionPercentage) {
106 super(id, name, accountNumber, maximumOverdraw, commissionPercentage);
107 }
108 public boolean takeALoan(double amount) {
109 boolean result = false;
110 if (amount <0) {
111 System.out.println("The amount provided is negative");
112 } else {
113 result = true;
114 }
115 return result;
116 }
117}
118==============================================================================================================================
119package accounts;
120
121import util.CommissionPercentages;
122
123public class RegularAccount extends LoanTakingAccount {
124 public RegularAccount(int id, String name, int accountNumber, double maximumOverdraw) {
125 super(id, name, accountNumber, maximumOverdraw, CommissionPercentages.REGULAR_COMMISSION_PERCENTAGE);
126 }
127}
128==============================================================================================================================
129package accounts;
130
131import util.CommissionPercentages;
132
133public class YoungAccount extends Account {
134 public YoungAccount(int id, String name, int accountNumber) {
135 super(id, name, accountNumber, 0, CommissionPercentages.YOUNG_COMMISSION_PERCENTAGE);
136 }
137}
138==============================================================================================================================
139import accounts.BusinessAccount;
140import accounts.RegularAccount;
141import accounts.StudentAccount;
142import accounts.YoungAccount;
143import bank.Bank;
144
145public class Program {
146 public static void main(String[] args) {
147 Bank bank = new Bank(4);
148 StudentAccount studentAccount = bank.openStudentAccount(325478516, "Gogo");
149 RegularAccount regularAccount = bank.openRegularAccount(354653156, "Lolo", 10000);
150 BusinessAccount businessAccount =bank.openBusinessAccount(654785478,"Momo",5000);
151 YoungAccount youngAccount =bank.openYoungAccount(254784152,"Koko");
152
153 bank.printAllBankAccountsWithNegativeBalance();
154 regularAccount.withdrawBalance(7000);
155 bank.printAllBankAccountsWithNegativeBalance();
156 }
157}
158