둘째 날 JAVA 원리금 균등상환 계산기
오늘은 원리금 균등상환을 해봄
변수명
-----------------------
대출원금 : money
연 이율: profit
상환기간(월) : month
-----------------------
공식은 money * (profit / 12) * (1 + profit / 12, month)^ / (1 + profit / 12, month)^ -1
^은 n승인데 표현할 방법이 마땅히 생각나지 않아서 이렇게 씀...
어쨋든 자바에서는 Math.pow라는 n승을 쉽게 계산해주는 좋은 함수가 있으므로 잘 쓰도록함
money * (profit / 12) * Math.pow(1 + profit / 12, month) /
Math.pow(1 + profit / 12, month) -1
이렇게 하면 되겠다.
이자만 갚을 시에는
money*profit*month/12
이 공식을 쓰면 되겠다.
이거 하기전에 삼각형 넓이 구하는 공식같은거도 했는데
전혀 쓸데가 없으므로 적지는 않겠다.
2일차 오전수업은 각설하고 소스코드를 적겠음
소스코드
----------------------------------------------------------------------
import java.util.Scanner;
public class Test7 {
public static void main(String arg[]) {
Scanner scan = new Scanner(System.in);
double money, profit, month, result, result2, top1, top2;
System.out.println("대출원금 입력");
money = scan.nextDouble();
System.out.println("연이율 입력");
profit = scan.nextDouble();
System.out.println("상환기간 입력");
month = scan.nextDouble();
top1 = money * (profit / 12);
top2 = Math.pow(1 + profit / 12, month);
result = (top1 * top2) / (top2 - 1);
result2 = money*profit*month/12;
System.out.println("원리금을 갚을시 매달 갚아야 할 돈은 : " + result);
System.out.println("이자만 갚을시 매달 갚아야 할 돈은 : " + result2);
}
}