Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Assessment Exercise 3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lui.bingham
Java Assessment Exercise 3
Commits
2eca50e4
Commit
2eca50e4
authored
May 16, 2022
by
lui.bingham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exercise 3
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
0 deletions
+133
-0
BankAccount.java
BankAccount.java
+63
-0
Main.java
Main.java
+10
-0
SavingsAccount.java
SavingsAccount.java
+60
-0
No files found.
BankAccount.java
0 → 100644
View file @
2eca50e4
import
java.text.DecimalFormat
;
public
class
BankAccount
{
int
accountNumber
;
String
name
;
double
balance
;
double
deposit
;
double
withdrawal
;
double
bankfees
;
private
static
final
DecimalFormat
PoundsFormat
=
new
DecimalFormat
(
"0.00"
);
public
BankAccount
(
int
accountNumber
,
String
name
,
double
balance
)
{
this
.
accountNumber
=
accountNumber
;
this
.
name
=
name
;
this
.
balance
=
balance
;
}
public
void
deposit
(
double
deposit
)
{
this
.
deposit
=
deposit
;
balance
=
balance
+
deposit
;
}
public
void
withdrawal
(
double
withdrawal
)
{
this
.
withdrawal
=
withdrawal
;
bankFees
();
}
public
void
addOverdraft
(
double
OverdraftLimit
)
{
if
((
balance
-
withdrawal
)
-
bankfees
<
-
OverdraftLimit
)
{
System
.
out
.
println
(
"Your specified withdrawal amount exceeds the overdraft limit. Please withdraw a lower amount."
);
}
else
{
balance
=
(
balance
-
withdrawal
)
-
bankfees
;
}
}
public
void
bankFees
()
{
if
(
balance
>
0.00
)
{
bankfees
=
(
balance
/
100
)
*
5
;
}
else
{
bankfees
=
(
balance
/
100
)
*
-
5
;
}
addOverdraft
(
100.00
);
}
public
void
display
()
{
System
.
out
.
println
(
"Account Number: "
+
accountNumber
);
System
.
out
.
println
(
"Account Owner: "
+
name
);
System
.
out
.
println
(
"Balance: £"
+
PoundsFormat
.
format
(
balance
));
}
}
Main.java
0 → 100644
View file @
2eca50e4
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
BankAccount
bankAccount
=
new
BankAccount
(
1
,
"Lui"
,
100.00
);
SavingsAccount
savingsAccount
=
new
SavingsAccount
(
1
,
"Lui"
,
100.00
);
bankAccount
.
withdrawal
(
50.00
);
bankAccount
.
display
();
savingsAccount
.
withdrawal
(
50.00
);
savingsAccount
.
display
();
}
}
SavingsAccount.java
0 → 100644
View file @
2eca50e4
import
java.text.DecimalFormat
;
public
class
SavingsAccount
{
int
accountNumber
;
String
name
;
double
balance
;
double
deposit
;
double
withdrawal
;
double
bankfees
;
double
interest
;
private
static
final
DecimalFormat
PoundsFormat
=
new
DecimalFormat
(
"0.00"
);
public
SavingsAccount
(
int
accountNumber
,
String
name
,
double
balance
)
{
this
.
accountNumber
=
accountNumber
;
this
.
name
=
name
;
this
.
balance
=
balance
;
}
public
void
deposit
(
double
deposit
)
{
this
.
deposit
=
deposit
;
balance
=
balance
+
deposit
;
interest
=
(
balance
/
100
)
*
5
;
accrueInterest
(
interest
);
}
public
void
withdrawal
(
double
withdrawal
)
{
this
.
withdrawal
=
withdrawal
;
if
(
withdrawal
>
balance
)
{
System
.
out
.
println
(
"You have insufficient funds to withdraw that amount. Your current balance is: £"
+
PoundsFormat
.
format
(
balance
));
}
if
(
withdrawal
>
100.00
)
{
System
.
out
.
println
(
"You can't withdraw more than £100.00 from your saving accounts. Please withdraw a lower amount."
);
}
else
{
balance
=
balance
-
withdrawal
;
interest
=
(
balance
/
100
)
*
-
5
;
accrueInterest
(
interest
);
}
}
public
void
accrueInterest
(
double
interest
)
{
balance
=
balance
+
interest
;
}
public
void
display
()
{
System
.
out
.
println
(
"Account Number: "
+
accountNumber
);
System
.
out
.
println
(
"Account Owner: "
+
name
);
System
.
out
.
println
(
"Balance: £"
+
PoundsFormat
.
format
(
balance
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment