Skip to content

Bonus functionality added #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Day-2/Employee.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use strict";
exports.__esModule = true;
var Employee = (function () {
function Employee(id, name, salary) {
function Employee(id, name, salary, star) {
this.id = id;
this.name = name;
this.salary = salary;
this.star = star;
console.log("Employee Rating :" + star);
}
Employee.prototype.printInfo = function () {
console.log(this.name + " gets " + this.salary);
Expand All @@ -15,6 +17,9 @@ var Employee = (function () {
Employee.prototype.getSalary = function () {
return this.salary;
};
Employee.prototype.getStar = function () {
return this.star;
};
return Employee;
}());
exports.Employee = Employee;
8 changes: 7 additions & 1 deletion Day-2/Employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ export class Employee {
id: number;
name: string;
salary: number;
constructor(id: number, name: string, salary: number) {
star: number;
constructor(id: number, name: string, salary: number,star: number) {
this.id = id;
this.name = name;
this.salary = salary;
this.star = star;
console.log("Employee Rating :"+star);
}
printInfo() {
console.log(`${this.name} gets ${this.salary}`);
Expand All @@ -16,5 +19,8 @@ export class Employee {
getSalary() {
return this.salary;
}
getStar(){
return this.star;
}
}

2 changes: 1 addition & 1 deletion Day-2/Organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Organization = (function () {
}
Organization.prototype.createEmployees = function () {
for (var i = 1; i <= 10; i++) {
var emp = new Employee_1.Employee(i, 'A' + i, i * 1000);
var emp = new Employee_1.Employee(i, 'A' + i, i * 1000, Math.floor(Math.random() * 5) + 1);
this.listOfEmployees.push(emp);
}
};
Expand Down
2 changes: 1 addition & 1 deletion Day-2/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Organization {
}
createEmployees() {
for (let i = 1; i <= 10; i++) {
let emp: Employee = new Employee(i, 'A' + i, i * 1000);
let emp: Employee = new Employee(i, 'A' + i, i * 1000, Math.floor(Math.random() * 5) + 1 );
this.listOfEmployees.push(emp);
}
}
Expand Down
6 changes: 6 additions & 0 deletions Day-2/salary-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ var Organization_1 = require("./Organization");
var salary_upgrader_1 = require("./salary-upgrader");
var org = new Organization_1.Organization('ABC');
org.createEmployees();
console.log("\n Employee Salary: ");
org.printEmployeesInfo();
var salaryUpgrader = new salary_upgrader_1.SalaryUpgrader();
console.log("\n Salary After Increment : ");
salaryUpgrader.incrementSalary(10, org.getEmployeeList());
org.printEmployeesInfo();
console.log("\n Salary After Bonus : ");
salaryUpgrader.addBonus(2, org.getEmployeeList());
//Check the workflow
org.printEmployeesInfo();
7 changes: 6 additions & 1 deletion Day-2/salary-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { SalaryUpgrader } from './salary-upgrader';

let org: Organization = new Organization('ABC');
org.createEmployees();
console.log("\n Employee Salary: ");
org.printEmployeesInfo();
let salaryUpgrader: SalaryUpgrader = new SalaryUpgrader();
console.log("\n Salary After Increment : ");
salaryUpgrader.incrementSalary(10, org.getEmployeeList());
org.printEmployeesInfo();

console.log("\n Salary After Bonus : ");
salaryUpgrader.addBonus(2,org.getEmployeeList());
//Check the workflow
org.printEmployeesInfo();
7 changes: 6 additions & 1 deletion Day-2/salary-upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ var SalaryUpgrader = (function () {
emp.updateSalary(newSalary);
});
};
SalaryUpgrader.prototype.addBonus = function () {
SalaryUpgrader.prototype.addBonus = function (percentRaise, empList) {
empList.map(function (emp) {
var oldSalary = emp.getSalary();
var newSalary = emp.getStar() >= 4 ? (oldSalary * percentRaise / 100) + oldSalary : oldSalary;
emp.updateSalary(newSalary);
});
};
return SalaryUpgrader;
}());
Expand Down
8 changes: 6 additions & 2 deletions Day-2/salary-upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export class SalaryUpgrader {
emp.updateSalary(newSalary);
})
}
addBonus() {

addBonus(percentRaise: number,empList: Employee[]) {
empList.map(emp=>{
let oldSalary = emp.getSalary();
let newSalary = emp.getStar() >= 4 ? (oldSalary*percentRaise/100) + oldSalary : oldSalary;
emp.updateSalary(newSalary);
})
}
}