Професионална програма
Olegati avatar Olegati 7 Точки

Problem 3 - Grooming Salon 90/100 (Java Advanced Exam - 26 June 2021)


На 3-та задача от Java Advanced Exam - 26 June 2021 гърми 8-мия тест. Предполаг проблема е в getPet(), въпреки че, на test case-овете работи безпроблемно. 

Линк към class-a GroomingSalon -> https://pastebin.com/STLVcrF1

Линк към class-a Pet -> https://pastebin.com/LjyUnEP5

Линк към class-a Main -> https://pastebin.com/e25RsK9C

Линк към Judge -> https://judge.softuni.org/Contests/Practice/Index/2997#2


Your task is to create a repository, which stores items by creating the classes described below.

First, write a Java class Pet with the following fields:

  • name: String
  • age: int
  • owner: String

The class constructor should receive all fields.  You need to create the appropriate getters and setters. The class should override the toString() method in the following format:

"{name} {age} - ({owner})"

Next, write a Java class GroomingSalon that has data (a collection, which stores the Pets). All entities inside the repository have the same fields. Also, the GroomingSalon class should have those fields:

  • capacity: int

The class constructor should receive capacity, also it should initialize the data with a new instance of the collection. Implement the following features:

  • Field dataList that holds added pets
  • Method add(Pet pet) – adds an entity to the data if there is an empty place in the grooming salon for the pet.
  • Method remove(String name) – removes the pet by given name, if such exists, and returns boolean.
  • Method getPet(String name, String owner) – returns the pet with the given name and owner or null if no such pet exists.
  • Getter getCount – returns the number of pets.
  • getStatistics()returns a String in the following format:
    • " The grooming salon has the following clients:
      name} {owner}
      name} {owner}



  • The combinations of names and owners will always be unique.
  • The age of the pets will always be positive.


This is an example of how the GroomingSalon class is intended to be used.

Sample code usage

// Initialize the repository

GroomingSalon salon = new GroomingSalon(20);


// Initialize entity

Pet dog = new Pet("Ellias", 5, "Tim");


// Print Pet

System.out.println(dog); // Ellias 5 - (Tim)


// Add Pet



// Remove Pet

System.out.println(salon.remove("Ellias")); // true

System.out.println(salon.remove("Pufa")); // false


Pet cat = new Pet("Bella", 2, "Mia");

Pet bunny = new Pet("Zak", 4, "Jon");





// Get Pet

Pet pet = salon.getPet("Bella", "Mia");

System.out.println(pet); // Bella 2 - (Mia)


// Count

System.out.println(salon.getCount()); // 2


// Get Statistics


// The grooming salon has the following clients:

//Bella Mia

//Zak Jon

Java Advanced
svephoto avatar svephoto 1109 Точки

Здравей, Olegati,


Проблемът идва от това, че в add метода на класа GroomingSalon проверяваш неточно за добавяне на животно:


public void add(Pet pet) {
    if (this.capacity > this.data.size() + 1) {


Трябва да махнеш " + 1", защото така вече излизаш извън големината на списъка.

Olegati avatar Olegati 7 Точки


svephoto avatar svephoto 1109 Точки