์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

6.9. ์—ฌ๋Ÿฌ ํ•จ์ˆ˜๋ฅผ ํด๋ž˜์Šค๋กœ ๋ฌถ๊ธฐ

๐Ÿœ๊ฐœ๋ฐœ์ž๋ผ๋ฉด/์ฑ…์„ ์ฝ์žโœ

by :ํ•ดํ”ผ๋ž˜๋น—๐Ÿพ 2021. 9. 26. 16:32

๋ณธ๋ฌธ

- ์—ฌ๋Ÿฌ ํ•จ์ˆ˜๋ฅผ ๋ฌถ๋Š” ๋ฐฉ๋ฒ• 

1) ํด๋ž˜์Šค๋กœ ๋ฌถ๊ธฐ

: ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๊ฐ์ฒด์˜ ํ•ต์‹ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ํŒŒ์ƒ ๊ฐ์ฒด๋“ค์„ ์ผ๊ด€๋˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 ์›๋ณธ ๋ฐ์ดํ„ฐ๊ฐ€ ์ฝ”๋“œ ์•ˆ์—์„œ ๊ฐฑ์‹ ๋  ๋•Œ - ํด๋ž˜์Šค๋กœ ๋ฌถ๊ธฐ

2) ๋ณ€ํ™˜ ํ•จ์ˆ˜๋กœ ๋ฌถ๊ธฐ(6.10)

: ์›๋ณธ ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„์„œ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๋ชจ๋‘ ๋„์ถœํ•œ ๋’ค, ๊ฐ๊ฐ์„ ์ถœ๋ ฅ ๋ฐ์ดํ„ฐ์˜ ํ•„๋“œ์— ๋„ฃ์–ด ๋ฐ˜ํ™˜ํ•œ๋‹ค.

3) ์ค‘์ฒฉ ํ•จ์ˆ˜ ํ˜•ํƒœ๋กœ ๋ฌถ๊ธฐ

: ํ…Œ์ŠคํŠธํ•˜๊ธฐ ๊นŒ๋‹ค๋กœ์šธ ์ˆ˜ ์žˆ๋‹ค.

4) ํ•จ์ˆ˜๋ฅผ ๊ฐ์ฒด์ฒ˜๋Ÿผ ํŒจํ„ด ์ด์šฉ(ํด๋ž˜์Šค ์ง€์›X)

 


๋ฐฉ๋ฒ•

1. ๊ณตํ†ต ๋ฐ์ดํ„ฐ ๋ ˆ์ฝ”๋“œ๋ฅผ ์บก์Аํ™”ํ•œ๋‹ค.

2. ๊ณตํ†ต ๋ ˆ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜ ๊ฐ๊ฐ์„ ์ƒˆ ํด๋ž˜์Šค๋กœ ์˜ฎ๊ธด๋‹ค.

3. ๋ฐ์ดํ„ฐ๋ฅผ ์กฐ์ž‘ํ•˜๋Š” ๋กœ์ง๋“ค์€ ํ•จ์ˆ˜๋กœ ์ถ”์ถœํ•ด์„œ ์ƒˆ ํด๋ž˜์Šค๋กœ ์˜ฎ๊ธด๋‹ค.

 


  ์—ฌ๋Ÿฌ ํ•จ์ˆ˜๋ฅผ ํด๋ž˜์Šค๋กœ ๋ฌถ๊ธฐ  

์–ด๋ ต๋‹ค...
// ๋ ˆ์ฝ”๋“œ
const reading = {customer:"ivan", quantity:10, month:5, year:2017};

//๋ ˆ์ฝ”๋“œ ์บก์Аํ™”
class Reading {
    constructor(data){
        this._customer = data.customer;
        this._quantity = data.quantity;
        this._month = data.month;
        this._year = data.year;
    }
    get customer(){return this._customer;}
    get quantity(){return this._quantity;}
    get month(){return this._month;}
    get year(){return this._year;}
    
    get baseCharge(){
        return baseRate(this.month,this.year)*this.quantity;
    }
    get taxableCharge(){
        return Math.max(0, this.baseCharge-taxThreshold(this.year));
    }

}

 

 

 

 

728x90

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ