2017년 10월 9일 월요일

이클립스 1주차 전기요금 계산기


1주차 수업 복습겸 만들어봤습니다.


        int kwhtex = 0, payBasic = 0, foundation = 0, elecCharge = 0, total  = 0;
        float def, vat = 0, kwh = 0;
     
        // 입력
        Scanner sc = new Scanner (System.in);
        System.out.print ("전기 사용량을 입력하세요 : ");
        kwh = sc.nextInt();
     
        sc.close();
        //계산
        if(kwh < 201) {
            payBasic = 910;
            def = 93.3F;
            kwhtex = (int)(kwh * def);
            elecCharge = payBasic + kwhtex;
            vat =  Math.round(0.1F * (kwhtex + payBasic)); //math.round 소수점 반올림
            foundation = (int)((0.037F * (kwhtex + payBasic))/10) * 10; //math.floor 원단위절삭
            total = (int) ((elecCharge + vat + foundation)/10)*10;
        }
     
        else if(kwh > 200 && kwh < 401) {
            payBasic = 1600;
            def = 187.9F;
            kwh = kwh - 200;
            kwhtex = 18660 + (int)(kwh * def) ;
            elecCharge = payBasic + kwhtex;
            vat =  Math.round(0.1F * (kwhtex + payBasic)); //math.round 소수점 반올림
            foundation = (int)((0.037F * (kwhtex + payBasic))/10) * 10; //math.floor 원단위절삭
            total = (int) ((elecCharge + vat + foundation)/10)*10;
        } else {
            payBasic = 7300;
            def = 280.6F;
            kwh = kwh - 400;
            kwhtex = 56240 + (int)(kwh * def);
            elecCharge = payBasic + kwhtex;
            vat =  Math.round(0.1F * (kwhtex + payBasic));
            foundation = (int)((0.037F * (kwhtex + payBasic))/10) * 10;
            total = (int) ((elecCharge + vat + foundation)/10)*10;
        }
       System.out.println ("기본 요금                  : " + payBasic +"원");
       System.out.println ("전력량 요금               : " + kwhtex+"원");
       System.out.println ("전기 요금계               : " + elecCharge+"원");
       System.out.printf  ("부가세                      : %.0f원\n", vat);
       System.out.println ("기반 기금                  : " + foundation+"원");
       System.out.println ("청구 금액(합계)    : " + total+"원");       
    }

}
Share:

0 개의 댓글:

댓글 쓰기

Scroll To Top