Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //VeterinaryClinic
- class VeterinaryClinic {
- constructor(clinicName, capacity){
- this.clinicName = clinicName;
- this.capacity = capacity;
- this.totalProfit = 0;
- this.clients = [];
- }
- newCustomer(ownerName, petName, kind, procedures){
- let check = true;
- if(this.capacity>0){
- for (let i = 0; i < this.clients.length; i++) {
- const element = this.clients[i];
- console.log(element);
- }
- if(check === true)
- let obj = {};
- obj[ownerName] = [
- petName,
- kind,
- procedures
- ];
- this.clients.push(obj);
- this.capacity--;
- // console.log(this.clients);
- return `Welcome ${petName}!`;
- }else{
- throw new Error(`Sorry, we are not able to accept more patients!`);
- }
- }
- onLeaving(ownerName, petName){
- if (this.clients.find(c => c.ownerName === ownerName && c.petName === petName)){
- for (let i = 0; i < this.clients.length; i++) {
- const element = this.clients[i];
- // console.log(element);
- if(ownerName === element.ownerName && petName === element.petName){
- if(element.procedures.length === 0){
- return `Sorry, there are no procedures for ${petName}!`
- }else{
- this.totalProfit = element.procedures.length*500;
- element.procedures = [];
- this.capacity++;
- // console.log(this.clients);
- }
- }
- }
- // console.log('da');
- return `Goodbye ${petName}. Stay safe!`;
- }else{
- throw new Error(`Sorry, there is no such client!`);
- }
- }
- toString(){
- let percentage = (10-this.capacity)*10;
- let arr = [];
- // let test = Object.keys(this.clients);
- // console.log(test);
- for (const key in this.clients) {
- let obj = {};
- const element = this.clients[key];
- obj[element.ownerName] = {petName: element.petName, kind: element.kind, procedures:element.procedures};
- console.log(obj);
- arr.push(obj);
- for (let i = 0; i < arr.length; i++) {
- console.log(arr[i]);
- // if(arr[i][element.ownerName] === element.ownerName){
- // console.log('da');
- // }
- }
- //arr.push([`${element.ownerName} with:`,
- // `---${element.petName} - a ${element.kind} that needs: ${element.procedures.join(', ')}`
- // ].join('\n'));
- console.log(arr);
- }
- let result = [
- `${this.clinicName} is ${percentage}% busy today!`,
- `Total profit: ${this.totalProfit.toFixed(2)}$`
- ];
- return result.concat(arr).join('\n');
- // console.log(this.clients);
- }
- }
- let clinic = new VeterinaryClinic('SoftCare', 10);
- //console.log(clinic);
- console.log(clinic.newCustomer('Jim Jones', 'Tom', 'Cat', ['A154B', '2C32B', '12CDB']));
- console.log(clinic.newCustomer('Anna Morgan', 'Max', 'Dog', ['SK456', 'DFG45', 'KS456']));
- console.log(clinic.newCustomer('Jim Jones', 'Tiny', 'Cat', ['A154B']));
- console.log(clinic.onLeaving('Jim Jones', 'Tiny'));
- console.log(clinic.toString());
- clinic.newCustomer('Jim Jones', 'Sara', 'Dog', ['A154B']);
- console.log(clinic.toString());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement