Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class VeterinaryClinic{
- constructor (clinicName, capacity){
- this.clinicName=clinicName;
- this.capacity=capacity;
- this.clients=[];
- this.totalProfit=0;
- this.currentWorkLoad=0;
- }
- newCustomer(ownerName, petName, kind, procedures){
- if (this.clients.length >=this.capacity) {
- throw new Error("Sorry, we are not able to accept more patients!")
- } else if (this.clients.find(a => a.petName===petName )) {
- let proceds=procedures.join(", ");
- let e= `This pet is already registered under ${ ownerName } name! ${ petName } is on our lists, waiting for ${proceds}.`;
- throw new Error(e)
- } else {
- this.clients.push({ownerName, petName, kind, procedures});
- return `Welcome ${ petName }!`;
- }
- }
- onLeaving (ownerName, petName) {
- let clientObj=this.clients.find(a => a.ownerName===ownerName);
- if (!this.clients.find(a => a.ownerName===ownerName)) {
- throw new Error("Sorry, there is no such client!")
- } else if (this.clients.find(a => a.ownerName===ownerName) && !clientObj.petName==petName) {
- throw new Error(`Sorry, there are no procedures for ${ petName }!`)
- } else {
- this.totalProfit += clientObj.procedures.length*500;
- const index = this.clients.indexOf(clientObj);
- if (index > -1) {
- this.clients.splice(index, 1);
- }
- return `Goodbye ${ petName }. Stay safe!`
- }
- }
- toString (){
- let busynesPercent=(+this.clients.length/+this.capacity)*100;
- let output=`${ this.clinicName } is ${ Math.floor(busynesPercent) }% busy today!`
- output+=`\nTotal profit: ${ this.totalProfit }$`
- let ownersInfo=this.clients.forEach(el => {
- let procedures2=el.procedures.join(", ");
- output+=`${ el.ownerName } with:
- ---${ el.petName } - a ${ el.kind } that needs: ${procedures2}"
- `
- });
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement