Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function Company() {  /*Класс Компания*/
  this.listEmployees = [];
}
Company.incorrectEmployees = function(message) {
  this.message = message;
}
Company.prototype.alreadyAddEmployee = function(employee) {
  for (var i = 0; i < this.listEmployees.length; i++) {
    if (this.listEmployees[i] == employee) {
      throw new Company.incorrectEmployees("Такой сотрудник уже есть!");
    }
  }
}
Company.prototype.nonexistentEmployee = function(employee) {
  for (var i = 0; i < this.listEmployees.length; i++) {
    if (this.listEmployees[i] == employee) {
      break;
    }
    
    if (i == this.listEmployees.length - 1) {
      throw new Company.incorrectEmployees("Несуществующий сотрудник!")
    }
  }
}
Company.prototype.addEmployee = function(employee) {
  this.alreadyAddEmployee(employee);
  
  this.listEmployees.push(employee);
}
Company.prototype.fireEmployee = function(employee) {
  this.nonexistentEmployee(employee);
  
  for (var i = 0; i < this.listEmployees.length; i++) { 
    if (this.listEmployees[i] == employee) {
      this.listEmployees.splice(i, 1);
    }
  }
}
Company.prototype.calcGenTime = function() {
  var genTime = 0;
  
  for (var i = 0; i < this.listEmployees.length; i++) {
    genTime += this.listEmployees[i].calcTime();
  }
  
  return genTime;
}
Company.prototype.calcGenSalary = function() {
  var genSalary = 0;
  
  for (var i = 0; i < this.listEmployees.length; i++) {
    genSalary += this.listEmployees[i].calcSalary();
  }
  
  return genSalary;
}
function Employee(expirience, baseRate, hoursOfMonth) { /*Класс Работник*/
  this.expirience = expirience;
  this.baseRate = baseRate;
  this.hoursOfMonth = hoursOfMonth;
}
Employee.prototype.calcSalary = function() {
  var genPercent = Math.floor(this.expirience) * 5 / 100 + 1;
  this.salary = this.baseRate * genPercent;
  
  return this.salary;
}
Employee.prototype.calcTime = function() {
  return this.hoursOfMonth;
}
var company1 = new Company();
var stas = new Employee(3, 900, 200);
var petya = new Employee(1, 1000, 300);
company1.addEmployee(petya);
company1.addEmployee(stas);
console.log(company1.calcGenTime());
console.log(company1.calcGenSalary());
company1.fireEmployee(stas);
console.log(company1.calcGenTime());
console.log(company1.calcGenSalary());
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers