diff options
Diffstat (limited to 'public/projects/js-small-apps/budget-app/lib/class-budget.js')
| -rw-r--r-- | public/projects/js-small-apps/budget-app/lib/class-budget.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/public/projects/js-small-apps/budget-app/lib/class-budget.js b/public/projects/js-small-apps/budget-app/lib/class-budget.js new file mode 100644 index 0000000..cde22fd --- /dev/null +++ b/public/projects/js-small-apps/budget-app/lib/class-budget.js @@ -0,0 +1,44 @@ +/** + * Budget class + * + * Create a new budget. + */ +class Budget { + #initial = 0; + #spent = 0; + #profit = 0; + + constructor(initial) { + this.#initial = Number.parseFloat(initial); + } + + set initial(number) { + this.#initial = Number.parseFloat(number); + } + + get initial() { + return this.#initial; + } + + set spent(number) { + this.#spent = Number.parseFloat(number); + } + + get spent() { + return this.#spent; + } + + set profit(number) { + this.#profit = Number.parseFloat(number); + } + + get profit() { + return this.#profit; + } + + remaining() { + return this.initial + this.profit - this.spent; + } +} + +export default Budget; |
