[Java] 양꼬치

Korangii·2024년 10월 26일

프로그래머스

목록 보기
19/21
post-thumbnail

문제 : 양꼬치


풀이 1번 : 계산

class Solution{
	int solution(int n, int k) {
		int answer = 0;
			answer=(n*12000)+((k-(n/10))*2000);
		return answer;
	}
}

풀이 2번 : 객체지향

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;
    }
}
profile
https://honeypeach.tistory.com/ 로 이전했습니다.

0개의 댓글