ํด๋์ค ์ค๊ณ
- ์ํ ์ํ์ ์์ ๋ฐ์ ์์ ์ ๊ธ, ์ฑ๋ฆฐ์ง๋ฐ์ค, ์ ๊ธฐ์๊ธ ๋ง๋ค๊ธฐ
- ์ํ ์ํ์ ์ผ์ด๋ฑ
ํฌ๋ฅผ ์ฐธ๊ณ ํ์์ต๋๋ค.
์ํ ์ํ
๊ธฐ๋ณธ ๊ธ๋ฆฌ(์ธ์ ) 12๊ฐ์ ๊ธฐ์ค
- ์์ ์ ๊ธ : ๊ธ๋ฆฌ 4.30%
- ์ฑ๋ฆฐ์ง ๋ฐ์ค : ๊ธ๋ฆฌ 2%
- ์ ๊ธฐ์๊ธ : ๊ธ๋ฆฌ 4.5%
๊ธฐ๋ฅ ๊ตฌํ
- ๊ฐ์
ํ ์ํ ์ ํ ([1] ์์ ์ ๊ธ [2] ์ฑ๋ฆฐ์ง๋ฐ์ค [3]์ ๊ธฐ์๊ธ)
- ๋ฉ์
๊ธ์ก ์
๋ ฅ
- ๊ฐ์
๊ธฐ๊ฐ ์
๋ ฅ
๊ฒฐ๊ณผ ์ถ๋ ฅ
- ๊ธ๋ฆฌ :
- ๊ฐ์
๊ธฐ๊ฐ :
- ๋ง๊ธฐ ๊ธ์ก(์ธ์ ) :
- ๋ง๊ธฐ ๊ธ์ก(์ธํ) :
* ๊ฐ์
๊ธฐ๊ฐ๊ณผ ๋ฉ์
๊ธ์ก์ ์ ํ์ ๋ฐ๋ก ๋์ง ์์์ต๋๋ค.
* ๋ง๊ธฐ๊ธ์ก์ ๋ณด๊ธฐ ํธํ๋๋ก ์ฒ ๋จ์๋ก ์ฝค๋ง๋ฅผ ์ฐ์์ต๋๋ค.
* ์์ฑ์์ ์ด๋ฆ์ ์
๋ ฅํ์ฌ ์ํ ๊ฐ์
์ ์ด๋ฆ์ด ๋์ค๋๋ก ํ์์ต๋๋ค.
Main
package ์ผ์ด๋ฑ
ํฌ;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
AccountProduct ac = null;
Scanner sc = new Scanner(System.in);
System.out.print("์ํ ์ ํ [1]์์ ์ ๊ธ [2]์ฑ๋ฆฐ์ง๋ฐ์ค [3]์๊ธ : ");
int sel = sc.nextInt();
switch(sel) {
case 1 : ac = new FreeSaving("์์ฝฉ๋ฏธ"); break;
case 2 : ac = new ChallengeSaving("์์ฝฉ๋ฏธ"); break;
case 3 : ac = new Deposit("์์ฝฉ๋ฏธ"); break;
default : System.out.println("์ํ์ ์๋ชป ์ ํํ์
จ์ต๋๋ค.");
}
System.out.print("๋ฉ์
๊ธ์ก : ");
int money = sc.nextInt();
System.out.print("๊ฐ์
๊ธฐ๊ฐ : ");
int period = sc.nextInt();
if(sel == 1 || sel == 2) ac.realRate(period);
ac.basicInterest(money,period);
ac.realInterest(money,period);
DecimalFormat formatter = new DecimalFormat("#,##0");
String maturityAmount = formatter.format(ac.maturityAmount());
String realMaturityAmount = formatter.format(ac.realMaturityAmount());
System.out.println("====== " + ac.getName() + " ๋์ ์ํ ๊ฐ์
์ ๋ณด ======");
System.out.printf("๊ธ๋ฆฌ : %.2f%s\n",(ac.rate * 100),"%");
System.out.printf("๊ฐ์
๊ธฐ๊ฐ : %d๊ฐ์\n", ac.period);
System.out.println("๋ง๊ธฐ๊ธ์ก(์ธ์ ) : " + maturityAmount + "์");
System.out.println("๋ง๊ธฐ๊ธ์ก(์ธํ) : " + realMaturityAmount + "์");
}
}
AccountProduct (๊ณ์ข ์ํ) - ๋ถ๋ชจ
package ์ผ์ด๋ฑ
ํฌ;
public class AccountProduct {
protected double rate; // ๊ธ๋ฆฌ
protected int period; // ๊ฐ์
๊ธฐ๊ฐ
protected int payment; // ์ ๋ฉ์
๊ธ์ก
protected int interestMoney; // ์ด์ ๊ธ์ก
protected int realInterestMoney; // ์ธํ ์ด์ ๊ธ์ก
protected int maturityAmount; // ์ธ์ ๋ง๊ธฐ ๊ธ์ก
protected int realMaturityAmount; // ์ธํ ๋ง๊ธฐ ๊ธ์ก
protected double realRate; // ์ธํ ์ด์์จ
protected String name; // ๊ณ ๊ฐ์ด๋ฆ
public String getName() {
return name;
}
// ์ธ์ ์ด์ ๊ธ์ก
public int basicInterest(int monthPayment, int period) {
this.payment = monthPayment;
this.period = period;
int sum = 0;
for(int i = period; i > 0; i--) {
interestMoney = (int)(monthPayment * rate) * i / period;
sum += interestMoney;
}
return sum;
}
// ๋ง๊ธฐ ๊ธ์ก(์ธ์ ) ๊ตฌํ๊ธฐ
public int maturityAmount() {
maturityAmount = payment * period + basicInterest(payment, period);
return maturityAmount;
}
// ์ธํ ์ด์ ๊ธ์ก ๊ตฌํ๊ธฐ
public int realInterest(int monthPayment, int period) {
this.payment = monthPayment;
this.period = period;
int sum = 0;
for(int i = period; i > 0; i--) {
realInterestMoney = (int)(monthPayment * realRate(period)) * i / period;
sum += realInterestMoney;
}
return sum;
}
// ์ธํ ๋ง๊ธฐ ๊ธ์ก ๊ตฌํ๊ธฐ
public int realMaturityAmount() {
realMaturityAmount = payment * period + realInterest(payment, period);
return realMaturityAmount;
}
// ์ ๊ธ ์ค์ ์ด์จ ๊ตฌํ๊ธฐ
public double realRate(int period) {
realRate = (rate * (period + 1) / 24) * (1 - 0.154);
return realRate;
}
}
FreeSaving(์์ ์ ๊ธ) - ์์
package ์ผ์ด๋ฑ
ํฌ;
public class FreeSaving extends AccountProduct {
FreeSaving(String name){
this.name = name;
rate = 0.043;
}
}
ChallengeSaving(์ฑ๋ฆฐ์ง ๋ฐ์ค) - ์์
package ์ผ์ด๋ฑ
ํฌ;
public class ChallengeSaving extends Saving {
ChallengeSaving(String name){
this.name = name;
rate = 0.02;
}
}
Deposit(์๊ธ) - ์์
package ์ผ์ด๋ฑ
ํฌ;
public class Deposit extends AccountProduct {
protected int payment; // ๋ฉ์
๊ธ์ก
Deposit(String name){
this.name = name;
rate = 0.045;
}
// ์ธ์ ์ด์ ๊ธ์ก
@Override
public int basicInterest(int payment, int period) {
this.payment = payment;
this.period = period;
interestMoney = (int)(payment * rate) * period / 12;
return interestMoney;
}
// ๋ง๊ธฐ ๊ธ์ก(์ธ์ )
@Override
public int maturityAmount() {
maturityAmount = payment + interestMoney;
return maturityAmount;
}
// ์ธํ ์ด์ ๊ธ์ก
@Override
public int realInterest(int monthPayment, int period) {
realInterestMoney = interestMoney - (int)(interestMoney * 0.154);
return realInterestMoney;
}
// ๋ง๊ธฐ ๊ธ์ก(์ธํ)
@Override
public int realMaturityAmount() {
realMaturityAmount = payment + realInterestMoney;
return realMaturityAmount;
}
}
์ถ๋ ฅํ๋ฉด