Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
hyebin-dev
java-practice
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
java-practice
/
week02
/
advanced
/
Account.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
42 lines (32 loc) · 1.37 KB
main
Breadcrumbs
java-practice
/
week02
/
advanced
/
Account.java
Copy path
Top
File metadata and controls
Code
Blame
42 lines (32 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package week02.advanced;
public class Account {
private String owner;
private int balance;
Account(String owner, int balance){
this.owner = owner;
this.balance = balance;
}
boolean transfer(Account target, int amount){
if (balance >= amount) {
this.balance -= amount; // 잔액 -이체금액
target.balance += amount; // target 잔액 + 이체금액
return true;
}
return false;
}
public String getOwner() {
return owner;
}
public int getBalance() {
return balance;
}
// 27단계 (심화): 은행 계좌 이체 트랜잭션
// 문제: Account.java (계좌주 owner, 잔액 balance)에, 다른 Account 객체와 이체할 금액을
// 매개변수로 받아 계좌 이체를 수행하는 transfer(Account target, int amount)메서드를
// 구현하세요. 이체에 성공하면 true, 잔액 부족으로 실패하면 false를 리턴하도록 만드세요.
// Bank.java에서 두 계좌를 만들고,이체 메서드를 호출한 뒤 리턴값에 따라 "이체 성공" 또는 "이체 실패"
// 를 출력하세요.
// 핵심 사고: 두 객체가 상호작용하며 서로의 상태를 변경하고, 작업의 성공/실패 여부를 리턴값으로 알려주는
// 트랜잭션 개념을 구현합니다.
// 힌트: 객체 간 상호작용, 메서드 리턴값(boolean), if문, private, getter, setter
}
You can’t perform that action at this time.