Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Person (name, age, isMale) {
- this.name = name;
- this.age = age;
- this.isMale = isMale;
- }
- Person.prototype.showPersonInfo = function () {
- console.log(this.name + ' is a ' + this.age + ' years old ' + (this.isMale === 'true' ? 'man' : 'woman') + '.');
- };
- function Student (name, age, isMale, score) {
- Person.call(this, name, age, isMale);
- this.score = score;
- }
- Student.prototype = Object.create(Person.prototype);
- Student.prototype.constructor = Student;
- Student.prototype.super = Person;
- Student.prototype.showStudentInfo = function () {
- this.showPersonInfo();
- console.log(this.name + ' has ' + this.score + ' scores.');
- };
- function Employee (name, age, isMale, daySalary) {
- Person.call(this, name, age, isMale);
- this.daySalary = daySalary;
- }
- Employee.prototype = Object.create(Person.prototype);
- Employee.prototype.constructor = Employee;
- Employee.prototype.super = Person;
- Employee.prototype.showEmployeeInfo = function () {
- this.showPersonInfo();
- console.log(this.name + ' earns ' + this.daySalary + ' lv per day.');
- };
- Employee.prototype.calculateOvertime = function (hours) {
- if (this.age < 18) {
- return 0;
- }
- var moneyPerHours = this.daySalary / 8;
- return (hours * moneyPerHours * 1.5).toFixed(2);
- };
- var arrPerson = [],
- id = 1;
- for (var i = 0; i < 10; i++) {
- arrPerson.push(new Person('Person' + id++, 15 + Math.round(Math.random() * 30), ['true', 'false'][Math.round(Math.random())]));
- }
- for (var i = 0; i < 2; i++) {
- arrPerson.push(new Person('Person' + id++,
- 15 + Math.round(Math.random() * 30),
- ['true', 'false'][Math.round(Math.random())]));
- arrPerson.push(new Student('Person' + id++,
- 15 + Math.round(Math.random() * 30),
- ['true', 'false'][Math.round(Math.random())],
- Math.round(Math.random() * 10)));
- arrPerson.push(new Employee('Person' + id++,
- 15 + Math.round(Math.random() * 30),
- ['true', 'false'][Math.round(Math.random())],
- 10 + Math.round(Math.random() * 20)));
- }
- arrPerson.forEach(function(person) {
- //console.log(person);
- if (person instanceof Student) {
- person.showStudentInfo();
- } else if (person instanceof Employee) {
- person.showEmployeeInfo();
- } else {
- person.showPersonInfo();
- }
- });
- console.log('-------------------------');
- for (var i = 0; i < arrPerson.length; i++) {
- //console.log(arrPerson[i])
- if (arrPerson[i] instanceof Employee) {
- console.log('For 2 hours overtime, ' + arrPerson[i].name + ' earns ' + arrPerson[i].calculateOvertime(2));
- }
- }
- //зад.5
- Person.prototype.showInfo = function () {
- console.log(this.name + ' is a ' + this.age + ' years old ' + (this.isMale === 'true' ? 'man' : 'woman') + '.');
- };
- Student.prototype = Object.create(Person.prototype);
- Student.prototype.constructor = Student;
- Student.prototype.super = Person;
- Student.prototype.showInfo = function () {
- Person.prototype.showInfo.call(this);
- console.log(this.name + ' has ' + this.score + ' scores.');
- };
- Employee.prototype = Object.create(Person.prototype);
- Employee.prototype.constructor = Employee;
- Employee.prototype.super = Person;
- Employee.prototype.showInfo = function () {
- Person.prototype.showInfo.call(this);
- console.log(this.name + ' earns ' + this.daySalary + ' lv per day.');
- };
- arrPerson.forEach(function(person) {
- person.showInfo();
- }
Add Comment
Please, Sign In to add comment