From 43eb1800627a2aef6e0d9aded0e4b685637fc910 Mon Sep 17 00:00:00 2001 From: jskonst Date: Sat, 5 Oct 2024 12:37:09 +0300 Subject: [PATCH] lab with classes sample --- rpgsaga/README.md | 6 ++++++ rpgsaga/saga/src/Phone.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 rpgsaga/README.md create mode 100644 rpgsaga/saga/src/Phone.ts diff --git a/rpgsaga/README.md b/rpgsaga/README.md new file mode 100644 index 00000000..dfa6360e --- /dev/null +++ b/rpgsaga/README.md @@ -0,0 +1,6 @@ +Phone +modelName +phoneNumber +weight +Dial() +AcceptCall() \ No newline at end of file diff --git a/rpgsaga/saga/src/Phone.ts b/rpgsaga/saga/src/Phone.ts new file mode 100644 index 00000000..06f25aee --- /dev/null +++ b/rpgsaga/saga/src/Phone.ts @@ -0,0 +1,32 @@ +export class Phone { + private _modelName: string; + private _phoneNumber: string; + private _weight: number; + + constructor(modelName: string, phoneNumber: string, weight: number) { + console.log('Constructor for Phone called'); + this._modelName = modelName; + this._phoneNumber = phoneNumber; + this.weight = weight; + } + + get weight(): number { + return this._weight; + } + + set weight(weight: number) { + if (weight > 0 && weight < 2000) { + this._weight = weight; + return; + } + throw new Error('weight out of range'); + } + + dial(number: string) { + console.log(`Dialing ${number}`); + } + + acceptCall() { + console.log(`Accepting incomming Call to ${this._phoneNumber}`); + } +}