playstation.ts

import { Product } from './product'

export class Playstation extends Product {
  generation:number = 0;
  constructor(names:string,generations:number,prices:number){
    super(names,prices)
    this.generation = generations;
  }
  getProfile(){
    return `${this.name} (Gen ${this.generation})`
  }
  getDiscountPrice(){
    return this.price - (this.price * (Playstation.DISCOUNT_PERCENT/100))
  }
}

product.ts

export class Product {
    readonly name:string = "";
    protected price:number = 0;
    static readonly DISCOUNT_PERCENT:number =10;
    constructor(names:string,prices:number=0){
        this.name = names;
        this.price = prices;
    }
    getPrice(){
        return this.price;  
    }
    setPrice(price: number){
        this.price = price;
   }
}

index.ts

import { Product } from './product'
import { Playstation } from './playstation'

const product = new Product('Generic Product')

console.log(product.name)
// Generic Product

console.log(product.getPrice())
// 0

product.setPrice(1000)

console.log(product.getPrice())
// 1000

const ps = new Playstation('PS5', 5, 17990)

console.log(ps.getProfile())
// PS5 (Gen 5)

console.log(ps.getPrice())
// 17990

ps.setPrice(18990)

console.log(ps.getPrice())
// 18990

console.log(ps.getDiscountPrice())
// 17091 (ถ้า Product.DISCOUNT_PERCENT = 10, คำนวณจาก 18990 - (18990 * 10 / 100))

README.md

# TypeScript Quiz — ข้อ 3 (1 คะแนน)
## 🎯 คำสั่ง

ให้นักเรียนสร้าง 2 class ได้แก่
- `Product` ในไฟล์ `product.ts` (parent class)
- `Playstation` ในไฟล์ `playstation.ts` (child class ที่ `extends Product`)

โดยต้องทำให้ไฟล์ `index.ts` ที่กำหนดให้ สามารถทำงานได้ถูกต้อง และได้ผลลัพธ์ตามที่คาดหวัง

ห้ามแก้ไขไฟล์ `index.ts`

## 📌 หมายเหตุสำคัญ

**ในไฟล์ `index.ts` มี comment (`//`) ที่แสดงตัวอย่างผลลัพธ์ที่คาดหวัง**

ให้นักเรียนอ่านผลลัพธ์จาก comment เหล่านั้น แล้วเขียน method logic ใน class ต่างๆ ให้สอดคล้องกับผลลัพธ์ที่แสดงไว้

**ตัวอย่าง:**
```typescript
console.log(ps.getProfile())
// PS5 (Gen 5)

จาก comment ด้านบน แสดงว่าผลลัพธ์ที่คาดหวังคือ "PS5 (Gen 5)" ดังนั้น method getProfile() ใน class Playstation ต้อง return ค่าในรูปแบบนี้

📁 โครงสร้างไฟล์ที่ต้องมี
p03/
 ├── product.ts
 ├── playstation.ts
 └── index.ts 

📌 เงื่อนไขบังคับ

  1. ต้อง export class Product และ export class Playstation extends Product
  2. ใน Product ต้องมี attribute name และ price โดย
  3. Product ต้องกำหนดค่าเริ่มต้นของ price เป็น 0
  4. Product ต้องมี constructor ที่รับ name และ price แบบ optional
  5. Product ต้องมี method:
  6. Product ต้องมี static readonly สำหรับเปอร์เซ็นต์ส่วนลด (เช่น DISCOUNT_PERCENT) เพื่อใช้ในการคำนวณ
  7. Playstation ต้องมี constructor รับค่า name, generation, price
  8. Playstation ต้องเขียน getProfile() และมี method getDiscountPrice() สำหรับคำนวณราคาหลังหักส่วนลด โดยใช้ค่า static readonly จาก Product
  9. ห้ามใช้ any
  10. ห้ามใช้ console.log ภายใน class