본문 바로가기

프로그래머스/lv0

옷가게 할인받기

/* 옷가게 할인받기
 * 옷가게는 10만 원 이상 사면 5%,
 * 30만 원 이상 사면 10%,
 * 50만 원 이상 사면 20%를 할인해줍니다.
 * 구매한 옷의 가격 price가 주어질 때, 지불해야 할 금액을 return
 *
 * price    result
 * 150,000  142,500
 * 580,000  464,000
 */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class programmer_0_49 {
    static int a1 = 150000;
    static int a2 = 580000;
    public int solution(int price) {
        int answer = 0;
        if(price >= 100000 && price < 300000)  answer = (int)(price * 0.95);
        else if(price >= 300000  && price < 500000)  answer = (int)(price * 0.9);
        else if(price >= 500000)    answer = (int)(price * 0.8);
        else answer = price;
        return answer;
    }
    public static void main(String args[]){
        programmer_0_49 t = new programmer_0_49();
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        System.out.println("result2 = " + t.solution(a2));
        System.out.println("---------------------------------------");
    }
}
cs

'프로그래머스 > lv0' 카테고리의 다른 글

머쓱이보다 키 큰 사람  (0) 2022.12.05
중복된 숫자의 개수  (0) 2022.12.05
아이스 아메리카노  (0) 2022.12.05
배열 뒤집기  (0) 2022.12.05
짝수 홀수 개수  (0) 2022.12.05