Advertisement
svetlio_top

Untitled

Aug 11th, 2020
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. //VeterinaryClinic
  2. class VeterinaryClinic {
  3. constructor(clinicName, capacity){
  4. this.clinicName = clinicName;
  5. this.capacity = capacity;
  6. this.totalProfit = 0;
  7. this.clients = [];
  8. }
  9. newCustomer(ownerName, petName, kind, procedures){
  10. let check = true;
  11.  
  12. if(this.capacity>0){
  13. for (let i = 0; i < this.clients.length; i++) {
  14. const element = this.clients[i];
  15. console.log(element);
  16. }
  17. if(check === true)
  18. let obj = {};
  19.  
  20. obj[ownerName] = [
  21. petName,
  22. kind,
  23. procedures
  24. ];
  25.  
  26. this.clients.push(obj);
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. this.capacity--;
  35. // console.log(this.clients);
  36. return `Welcome ${petName}!`;
  37.  
  38. }else{
  39. throw new Error(`Sorry, we are not able to accept more patients!`);
  40. }
  41.  
  42. }
  43. onLeaving(ownerName, petName){
  44.  
  45.  
  46.  
  47. if (this.clients.find(c => c.ownerName === ownerName && c.petName === petName)){
  48.  
  49. for (let i = 0; i < this.clients.length; i++) {
  50. const element = this.clients[i];
  51. // console.log(element);
  52. if(ownerName === element.ownerName && petName === element.petName){
  53. if(element.procedures.length === 0){
  54. return `Sorry, there are no procedures for ${petName}!`
  55. }else{
  56. this.totalProfit = element.procedures.length*500;
  57. element.procedures = [];
  58. this.capacity++;
  59. // console.log(this.clients);
  60. }
  61. }
  62. }
  63. // console.log('da');
  64. return `Goodbye ${petName}. Stay safe!`;
  65. }else{
  66. throw new Error(`Sorry, there is no such client!`);
  67. }
  68. }
  69. toString(){
  70. let percentage = (10-this.capacity)*10;
  71.  
  72. let arr = [];
  73.  
  74. // let test = Object.keys(this.clients);
  75. // console.log(test);
  76. for (const key in this.clients) {
  77. let obj = {};
  78. const element = this.clients[key];
  79. obj[element.ownerName] = {petName: element.petName, kind: element.kind, procedures:element.procedures};
  80. console.log(obj);
  81.  
  82. arr.push(obj);
  83. for (let i = 0; i < arr.length; i++) {
  84. console.log(arr[i]);
  85.  
  86. // if(arr[i][element.ownerName] === element.ownerName){
  87. // console.log('da');
  88. // }
  89. }
  90. //arr.push([`${element.ownerName} with:`,
  91. // `---${element.petName} - a ${element.kind} that needs: ${element.procedures.join(', ')}`
  92. // ].join('\n'));
  93. console.log(arr);
  94. }
  95. let result = [
  96. `${this.clinicName} is ${percentage}% busy today!`,
  97. `Total profit: ${this.totalProfit.toFixed(2)}$`
  98. ];
  99.  
  100. return result.concat(arr).join('\n');
  101. // console.log(this.clients);
  102. }
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement