Advertisement
Guest User

Untitled

a guest
Aug 9th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. class VeterinaryClinic{
  2. constructor (clinicName, capacity){
  3. this.clinicName=clinicName;
  4. this.capacity=capacity;
  5. this.clients=[];
  6. this.totalProfit=0;
  7. this.currentWorkLoad=0;
  8. }
  9. newCustomer(ownerName, petName, kind, procedures){
  10. if (this.clients.length >=this.capacity) {
  11. throw new Error("Sorry, we are not able to accept more patients!")
  12. } else if (this.clients.find(a => a.petName===petName )) {
  13. let proceds=procedures.join(", ");
  14. let e= `This pet is already registered under ${ ownerName } name! ${ petName } is on our lists, waiting for ${proceds}.`;
  15. throw new Error(e)
  16. } else {
  17. this.clients.push({ownerName, petName, kind, procedures});
  18. return `Welcome ${ petName }!`;
  19. }
  20. }
  21. onLeaving (ownerName, petName) {
  22. let clientObj=this.clients.find(a => a.ownerName===ownerName);
  23.  
  24. if (!this.clients.find(a => a.ownerName===ownerName)) {
  25. throw new Error("Sorry, there is no such client!")
  26. } else if (this.clients.find(a => a.ownerName===ownerName) && !clientObj.petName==petName) {
  27. throw new Error(`Sorry, there are no procedures for ${ petName }!`)
  28. } else {
  29. this.totalProfit += clientObj.procedures.length*500;
  30. const index = this.clients.indexOf(clientObj);
  31. if (index > -1) {
  32. this.clients.splice(index, 1);
  33. }
  34.  
  35. return `Goodbye ${ petName }. Stay safe!`
  36. }
  37.  
  38. }
  39.  
  40.  
  41.  
  42. toString (){
  43. let busynesPercent=(+this.clients.length/+this.capacity)*100;
  44. let output=`${ this.clinicName } is ${ Math.floor(busynesPercent) }% busy today!`
  45. output+=`\nTotal profit: ${ this.totalProfit }$`
  46. let ownersInfo=this.clients.forEach(el => {
  47. let procedures2=el.procedures.join(", ");
  48. output+=`${ el.ownerName } with:
  49. ---${ el.petName } - a ${ el.kind } that needs: ${procedures2}"
  50. `
  51. });
  52. return output;
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement