Untitled
unknown
plain_text
a year ago
1.0 kB
8
Indexable
import * as fs from 'fs';
class Employee {
id: number;
name: string;
role: string;
constructor(id: number, name: string, role: string) {
this.id = id;
this.name = name;
this.role = role;
}
calculatePay(): number {
if (this.role === 'developer') {
return 5000;
} else if (this.role === 'manager') {
return 8000;
} else {
return 3000;
}
}
save(): void {
const data = `ID: ${this.id}, Name: ${this.name}, Role: ${this.role}`;
fs.writeFileSync(`${this.id}.txt`, data);
}
}
class EmployeeReport {
employee: Employee;
constructor(employee: Employee) {
this.employee = employee;
}
report(): void {
console.log(
`Report for ${this.employee.name}, Role: ${this.employee.role}, Pay: ${this.employee.calculatePay()}`
);
}
}
// Usage example
const e1 = new Employee(1, 'Alice', 'developer');
const e2 = new Employee(2, 'Bob', 'manager');
e1.save();
e2.save();
const report = new EmployeeReport(e1);
report.report();
Editor is loading...
Leave a Comment