0% found this document useful (0 votes)
16 views4 pages

Classes and Objects

The document contains a JavaScript code implementation of classes and objects, specifically defining a 'Person' class and an 'Employee' class that extends it. The 'Employee' class includes methods for calculating allowances and salary details, and it maintains private properties for employee data. Additionally, the document demonstrates the creation of employee instances and outputs their salary reports.

Uploaded by

24mx347
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Classes and Objects

The document contains a JavaScript code implementation of classes and objects, specifically defining a 'Person' class and an 'Employee' class that extends it. The 'Employee' class includes methods for calculating allowances and salary details, and it maintains private properties for employee data. Additionally, the document demonstrates the creation of employee instances and outputs their salary reports.

Uploaded by

24mx347
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exercise - 9 Classes and Objects

Balaji V 24mx305
JavaScript Code:
class Person {
constructor(name, age) {
[Link] = name;
[Link] = age;
}

displayPersonalDetail() {
[Link](`Name: ${[Link]}, Age: ${[Link]}`);
}
}

class Employee extends Person {


static empCount = 0;

constructor(name, age, basicPay) {


super(name, age);
this.#empNumber = ++[Link];
this.#basicPay = basicPay;
this.#da = 0;
this.#hra = 0;
this.#netPay = 0;
this.#loan = 0;

this.#calculateAllowances();
this.#calculateSalary();
}

#empNumber;
#basicPay;
#da;
#hra;
#netPay;
#loan;

#calculateAllowances() {
this.#da = this.#basicPay * 0.1;
this.#hra = this.#basicPay * 0.2;
}
Exercise - 9 Classes and Objects
Balaji V 24mx305
#calculateSalary() {
const grossPay = this.#basicPay + this.#da + this.#hra;

this.#loan = grossPay > 3000 ? grossPay * 0.05 : 0;

this.#netPay = grossPay - this.#loan;


}

displaySalaryDetails() {
[Link](`Employee Number: ${this.#empNumber}`);
[Link]();
[Link](`Gross Pay: ${this.#basicPay + this.#da + this.#hra}`);
[Link](`Loan Deduction: ${this.#loan}`);
[Link](`Net Pay: ${this.#netPay}`);
}
}

const employees = [];

[Link](new Employee("Alice", 30, 3200));


[Link](new Employee("Bob", 28, 2800));
[Link](new Employee("Charlie", 35, 4500));

[Link](`Salary Report of << ${[Link]} >> Employees`);


[Link]("Employee Number | Employee Name | Gross Pay | Loan Deduction
| Net Pay");

[Link](employee => {
[Link]();
[Link]("-----------------------------");
});
Exercise - 9 Classes and Objects
Balaji V 24mx305
Output:
Exercise - 9 Classes and Objects
Balaji V 24mx305
Diagram:

You might also like