Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
oop
exercises
Commits
9a689be0
Commit
9a689be0
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: ex2 serie2 finished
parent
e0df49de
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
serie2/ex2/.gitignore
+1
-0
1 addition, 0 deletions
serie2/ex2/.gitignore
serie2/ex2/Account.java
+65
-0
65 additions, 0 deletions
serie2/ex2/Account.java
with
66 additions
and
0 deletions
serie2/ex2/.gitignore
0 → 100644
+
1
−
0
View file @
9a689be0
*.class
This diff is collapsed.
Click to expand it.
serie2/ex2/Account.java
0 → 100644
+
65
−
0
View file @
9a689be0
public
class
Account
{
private
String
owner
;
private
int
amount
;
public
String
getOwner
()
{
return
owner
;
}
public
int
getAmount
()
{
return
amount
;
}
public
Account
(
String
owner
)
{
this
.
owner
=
owner
;
}
public
Account
(
String
owner
,
int
amount
)
{
this
(
owner
);
amountAuthorizedCreation
(
amount
);
this
.
amount
=
amount
;
}
public
static
void
amountAuthorizedCreation
(
int
amount
)
{
if
(
amount
<
0
)
{
throw
new
RuntimeException
(
"Amount has to be greater than or equal to 0.-"
);
}
}
public
static
void
amountAuthorizedOperations
(
int
amount
)
{
if
(
amount
<=
-
2000
)
{
throw
new
RuntimeException
(
"Amount has to be greater than or equal to -2000.-"
);
}
}
public
void
withdraw
(
int
amountToRetrieve
)
{
amountAuthorizedOperations
(
this
.
amount
-
amountToRetrieve
);
this
.
amount
-=
amountToRetrieve
;
}
public
void
deposit
(
int
addAmount
)
{
amountAuthorizedOperations
(
this
.
amount
+
addAmount
);
this
.
amount
+=
addAmount
;
}
public
void
transfer
(
int
amount
,
Account
dst
)
{
dst
.
deposit
(
amount
);
withdraw
(
amount
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
return
(
obj
instanceof
Account
)
&&
(((
Account
)
obj
).
getOwner
()
==
this
.
owner
)
&&
(((
Account
)
obj
).
getAmount
()
==
this
.
amount
);
}
public
static
void
main
(
String
[]
args
)
{
Account
p1
=
new
Account
(
"Person 1"
,
100
);
Account
p2
=
new
Account
(
"Person 2"
,
100
);
p1
.
transfer
(
2101
,
p2
);
System
.
out
.
println
(
p1
.
getAmount
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment