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
/
Drink.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
49 lines (44 loc) · 1.77 KB
main
Breadcrumbs
java-practice
/
week02
/
advanced
/
Drink.java
Copy path
Top
File metadata and controls
Code
Blame
49 lines (44 loc) · 1.77 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
43
44
45
46
47
48
49
package week02.advanced;
public class Drink {
private String name;
private int price;
private int stock;
Drink(String name, int price, int stock){
this.name = name;
this.price = price;
this.stock = stock;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
}
// 30단계 (심화): 자판기 시스템의 완성
// 문제:
// 1. Drink.java: 이름(name), 가격(price), 재고(stock)를 private 멤버와
// Getter/Setter로 가집니다.
// 2. VendingMachine.java: Drink 객체 배열(drinks)과 투입된 금액(money)을
// 멤버로 가집니다. 음료를 세팅하는 setupDrinks() 메서드, 돈을 투입하는 insertMoney(int m),
// 음료를 선택하는 selectDrink(int index) 메서드를 구현하세요. selectDrink는 성공 시
// 거스름돈, 재고 부족 시 -1, 금액 부족 시 -2를 리턴합니다.
// 3. VendingMachineTest.java에서 자판기를 만들고, while 루프를 통해 사용자 상호작용
// (돈 투입, 음료 선택)을 시뮬레이션하세요. selectDrink의 리턴값에 따라 다른 메시지를
// 출력해야 합니다.
// 핵심 사고: 여러 클래스와 복잡한 상태(재고, 돈)를 종합적으로 관리하며, 메서드의 다양한 리턴값을 통해
// 프로그램의 흐름을 제어하는 완성도 높은 프로그램을 설계합니다.
// 힌트: 종합적인 클래스 설계, 상태 관리, 메서드 리턴값을 이용한 로직 분기, while문,
// if-else if-else, input
You can’t perform that action at this time.