삼성SDS_멀티캠퍼스/Java

9일 차 class로 원리금 균등상환 만들기

박성우기 2015. 9. 17. 17:07
반응형


class Loan {


private double money; // 대출원금

private double profit; // 대출이율

private double month; // 개월 수


public double getMoney() {

return money;

}


public void setMoney(int money) {

this.money = money;

}


public double getProfit() {

return profit;

}


public void setProfit(int profit) {

this.profit = profit;

}


public double getMonth() {

return month;

}


public void setMonth(int month) {

this.month = month;

}


@Override

public String toString() {

return "Loan [money=" + money + ", profit=" + profit + ", month=" + month + "]";

}


public double rePayment() {


double result, result2, top, top2;

top = money * (profit / 12);

top2 = Math.pow(1 + profit / 12, month);

result2 = money * profit * month / 12;


return result2;


}


public double reProfit() {


this.profit = profit / 100.0;

double result, result2, top, top2;

top = money * (profit / 12);

top2 = Math.pow(1 + profit / 12, month);

result = (top * top2) / (top2 - 1);


return result;


}


public double rePay(double io) {


double result;


result = month--;


return result;

}


}

import java.util.Scanner;

public class Test8 {

public static void main(String[] args) {
// TODO Auto-generated method stub

double inputMoney;
Scanner scan = new Scanner(System.in);

System.out.println("갚은 금액을 입력하세요");
inputMoney = scan.nextInt();

double rePay, rePro, rePut;
Loan ln = new Loan();
ln.setMoney(10000);
ln.setProfit(1);
ln.setMonth(7);
rePay = ln.rePayment();
rePro = ln.reProfit();
rePut = ln.rePay(inputMoney);

System.out.println("원리금 균등상환시 " + rePay);
System.out.println("이자만 갚을시 " + rePro);
System.out.println("남은 원리금 균등상환 잔금은 " + (rePay - inputMoney));
System.out.println(ln);
System.out.println(ln.getMoney() - inputMoney);
}

}





반응형