코딩 테스트 [ 연습 ]

프로그래머스 - 입문 - 옷가게 할인 받기

monimoni 2022. 12. 28. 23:30

 

 


 

 

 

더보기
class Solution {
    
    // 문제 :
    // + 10만 원 이상 사면 5%,
    // + 30만 원 이상 사면 10%,
    // + 50만 원 이상 사면 20%를 할인해줄 때 금액을 return하시오
    
    public int solution(int price) {
        
        // + 1. 조건문을 활용해 price별로 할인 금액을 다르게 한다.
        
        double answer = 0;
        // + 최종 금액을 저장할 변수 생성
        
        if ( price < 100000 ) {
            answer = price;
        } else if ( ( 100000 <= price ) && ( price < 300000 ) ) {
            answer = price * 0.95;
        } else if ( price < 500000 ) {
            answer = price * 0.9;
        } else {
            answer = price * 0.8;
        } // if - else if - else
        
        return (int) answer;
        
    } // solution
    
} // end class

 

 

728x90