... | ... | @@ -20,90 +20,18 @@ |
|
|
public static int main(String[] args)
|
|
|
```
|
|
|
|
|
|
-
|
|
|
- 음식을 파는 음식점이 있습니다. 음식의 속성에는 이름, 가격이 있습니다. 음식점은 새로운 메뉴를 추가할 수 있고, 메뉴를 제공하며, 음식을 주문 할 수 있습니다. 이를 객체 지향으로 구현하세요.
|
|
|
|
|
|
- 위 음식점은 종업원이 1명이라서 주문과 요리를 동시에 할 수 없었습니다. 그래서 새로 요리사를 구했습니다. 이제 바로 요리를 제공하지 않고, 대기표만 발급 후 다음 주문을 받을 수 있습니다. 이후 요리가 끝나면 손님을 호출하여 음식을 제공합니다. 또한 음식의 속성에는 조리 시간이 추가 되었습니다. (※hint: interface, thread)
|
|
|
|
|
|
- 판매하던 음식 중에 피자가 가장 잘 팔려서, 업종을 피자 가게로 전문화 하였습니다. 피자는 이름,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
package com.company;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
class Fruit {
|
|
|
private String name;
|
|
|
private int price;
|
|
|
|
|
|
Fruit(String name, int price) {
|
|
|
this.name = name;
|
|
|
this.price = price;
|
|
|
}
|
|
|
|
|
|
int getPrice() {
|
|
|
return price;
|
|
|
}
|
|
|
|
|
|
String getName() {
|
|
|
return name;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class FruitDealer {
|
|
|
|
|
|
final private ArrayList<Fruit> fruits;
|
|
|
|
|
|
FruitDealer(ArrayList<Fruit> fruits) {
|
|
|
this.fruits = fruits;
|
|
|
}
|
|
|
|
|
|
ArrayList<String> getFruitsNames() {
|
|
|
return fruits
|
|
|
.stream()
|
|
|
.map(Fruit::getName)
|
|
|
.collect(Collectors.toCollection(ArrayList::new));
|
|
|
}
|
|
|
|
|
|
int getFruitPrice(String fruitsName) {
|
|
|
return fruits.stream()
|
|
|
.filter(f -> f.getName().equals(fruitsName))
|
|
|
.findFirst()
|
|
|
.orElse(null)
|
|
|
.getPrice();
|
|
|
}
|
|
|
|
|
|
int buyFruit(String fruitName, int money) {
|
|
|
int fruitPrice = this.getFruitPrice(fruitName);
|
|
|
if (money > fruitPrice) {
|
|
|
return money - fruitPrice;
|
|
|
}
|
|
|
return money;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
private final static String WHAT_I_WANT_FRUIT = "바나나";
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
int myMoney = 500;
|
|
|
|
|
|
FruitDealer fruitDealer = new FruitDealer(new ArrayList<Fruit>() {{
|
|
|
add(new Fruit("사과", 300));
|
|
|
add(new Fruit("바나나", 200));
|
|
|
add(new Fruit("포도", 400));
|
|
|
}});
|
|
|
|
|
|
String fruitName = fruitDealer.getFruitsNames().stream()
|
|
|
.filter(s -> s.equals(WHAT_I_WANT_FRUIT))
|
|
|
.findFirst()
|
|
|
.orElse(null);
|
|
|
|
|
|
int fruitPrice = fruitDealer.getFruitPrice(fruitName);
|
|
|
|
|
|
if (myMoney > fruitPrice) {
|
|
|
myMoney = fruitDealer.buyFruit(fruitName, myMoney);
|
|
|
}
|
|
|
|
|
|
System.out.println(myMoney);
|
|
|
}
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |