상세 컨텐츠

본문 제목

[람다 함수] 돈바꾸기

자바

by esoesmio 2023. 4. 4. 19:57

본문

//// 왜 action에 conver c를 집어넣는가?

 

package april4;

public class zclass4 {

    public static void main(String[] args) {

action(moneyconvertor::convert);

        action(moneyconvertor::instanceconvert);


    }

    public static void action(convertor con){

        int result = con.conv(10000,'$');
        System.out.println("변환된 돈 :  $" + result);

    }
}


class  moneyconvertor{
    public static int convert(int money, char c){

        int convertmoney = 0;
        switch(c){
            case'$':
            convertmoney = money/1300;
            break;


            case'\\':
                convertmoney = money *1300;
                break;

            default:
                convertmoney =-1;
                break;
        }
        return convertmoney;
    }


    public static int instanceconvert(int money, char c){



            int convertmoney = 0;
            switch(c){
                case'$':
                    convertmoney = money/1300;
                    break;


                case'\\':
                    convertmoney = money *1300;
                    break;

                default:
                    convertmoney =-1;
                    break;
            }
            return convertmoney;









}}


interface  convertor{
    int conv(int a, char c);


}

관련글 더보기

댓글 영역