오늘이라도
[6일차][프로그래머스, 120830번, Lv. 0] 양꼬치 본문
반응형
문제
내 풀이
채점 결과
피드백
class Solution {
public int solution(int n, int k) {
int lambTotalPrice = totalPrice(Menu.LAMB, n);
int drinkTotalPrice = totalPrice(Menu.DRINK, k);
int discountPrice = discount(Menu.DRINK, n);
int totalPay = lambTotalPrice + drinkTotalPrice - discountPrice;
return totalPay;
}
private int totalPrice(Menu menu, int quantity) {
return menu.getPrice() * quantity;
}
private int discount(Menu menu, int lambQuantity) {
// 양꼬치 10인분에 음료수 하나
int point = lambQuantity / 10;
return menu.getPrice() * point;
}
}
enum Menu {
LAMB("양꼬치", 12000),
DRINK("음료수", 2000);
private final String name;
private final int price;
Menu(String name, int price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public int getPrice() {
return price;
}
}
좋은 객체지향 풀이가 있어서 적어둡니다
반응형
'개발 공부 > 코딩테스트' 카테고리의 다른 글
[6일차][프로그래머스, 120833번, Lv. 0] 배열 자르기 (0) | 2022.12.22 |
---|---|
[6일차][프로그래머스, 120831번, Lv. 0] 짝수의 합 (1) | 2022.12.22 |
[6일차][프로그래머스, 120829번, Lv. 0] 각도기 (0) | 2022.12.22 |
[6일차][프로그래머스, 120826번, Lv. 0] 특정 문자 제거하기 (0) | 2022.12.22 |
[5일차][프로그래머스, 120825번, Lv. 0] 문자 반복 출력 (0) | 2022.12.21 |