enum CoffeeMenu {
AMERICANO(2000) {
@Override
public int totalPrice(int optionOrder, int normalOrder) {
return 2000 * (normalOrder + optionOrder * 2) + (optionOrder == 0 ? 0 : 300);
}
},
LATTE(3000) {
@Override
public int totalPrice(int optionOrder, int normalOrder) {
return 3000 * (normalOrder + optionOrder * 2) + (optionOrder == 0 ? 0 : 500);
}
},
MOCHA(4000) {
@Override
public int totalPrice(int optionOrder, int normalOrder) {
return 4000 * (normalOrder + optionOrder * 2) + (optionOrder == 0 ? 0 : 1000);
}
},
COLDBREW(4500) {
@Override
public int totalPrice(int optionOrder, int normalOrder) {
return 4500 * (normalOrder + optionOrder * 2) + (optionOrder == 0 ? 0 : 200);
}
};
private final int price;
CoffeeMenu(int price) {
this.price = price;
}
public int getPrice() {
return price;
}
public abstract int totalPrice(int optionOrder, int normalOrder);
}
public class home10 {
public static void main(String[] args) {
int americanoTotalPrice = CoffeeMenu.AMERICANO.totalPrice(2, 1);
int latteTotalPrice = CoffeeMenu.LATTE.totalPrice(1, 1);
int mochaTotalPrice = CoffeeMenu.MOCHA.totalPrice(2, 0);
int coldBrewTotalPrice = CoffeeMenu.COLDBREW.totalPrice(2, 2);
System.out.println("아메리카노 2잔(아이스 300 추가), 라떼 1잔(아이스 500 추가), 모카 2잔(휘핑 1000 추가), 콜드브루 2잔(시럽 200 추가) 주문 시 총 가격:");
System.out.println("아메리카노: " + americanoTotalPrice + "원");
System.out.println("라떼: " + latteTotalPrice + "원");
System.out.println("모카: " + mochaTotalPrice + "원");
System.out.println("콜드브루: " + coldBrewTotalPrice + "원");
}
}
댓글 영역