Last active
December 8, 2025 19:27
-
-
Save ikotse-code/92762978cb908cb099fe8b8366692025 to your computer and use it in GitHub Desktop.
HW04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Assignment #1 | |
| class Calculator { | |
| // for static methods no need to create a new instance | |
| static additionReturnNumber(num1: number, num2: number): number { | |
| return num1 + num2; | |
| } | |
| static additionReturnString(num1: number, num2: number): string { | |
| const resultNum: number = num1 + num2; | |
| return `Result is: ${resultNum}`; | |
| } | |
| static additionVoid(num1: number, num2: number): void { | |
| const result: number = num1 + num2; | |
| console.log("Result is: " +result); | |
| } | |
| static isGreater(a: number, b: number): boolean { | |
| return a > b; | |
| } | |
| } | |
| console.log(Calculator.additionReturnNumber(1, 3)); | |
| console.log(Calculator.additionReturnString(1, 3)); | |
| Calculator.additionVoid(1, 3); | |
| console.log(Calculator.isGreater(1,3)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Assignment #2 | |
| class Product { | |
| //define fields | |
| name: string; | |
| price: number; | |
| quantity: number; | |
| //initialize | |
| constructor(name: string, price: number, quantity: number) { | |
| this.name = name; | |
| this.price = price; | |
| this.quantity = quantity; | |
| } | |
| isInStock(): boolean { | |
| return this.quantity > 0; | |
| } | |
| } | |
| const productA = new Product("ProductA", 15, 12); | |
| const productB = new Product("ProductB", 15, 0); | |
| console.log(productA.isInStock()); | |
| console.log(productB.isInStock()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You did a great job! Happy to see that you used different types of methods.