GiantStepDEV
article thumbnail

ํด๋ž˜์Šค ์„ค๊ณ„

  • ์€ํ–‰ ์ƒํ’ˆ์„ ์ƒ์† ๋ฐ›์•„ ์ž์œ ์ ๊ธˆ, ์ฑŒ๋ฆฐ์ง€๋ฐ•์Šค, ์ •๊ธฐ์˜ˆ๊ธˆ ๋งŒ๋“ค๊ธฐ
  • ์€ํ–‰ ์ƒํ’ˆ์€ ์ผ€์ด๋ฑ…ํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์€ํ–‰ ์ƒํ’ˆ

๊ธฐ๋ณธ ๊ธˆ๋ฆฌ(์„ธ์ „) 12๊ฐœ์›” ๊ธฐ์ค€
  1. ์ž์œ  ์ ๊ธˆ : ๊ธˆ๋ฆฌ 4.30%
  2. ์ฑŒ๋ฆฐ์ง€ ๋ฐ•์Šค : ๊ธˆ๋ฆฌ 2%
  3. ์ •๊ธฐ์˜ˆ๊ธˆ : ๊ธˆ๋ฆฌ 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;
    }
}

์ถœ๋ ฅํ™”๋ฉด

profile

GiantStepDEV

@kongmi

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!