Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

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}

   (…)"

Constraints

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


Examples

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

salon.add(dog);

 

// 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");

 

salon.add(cat);

salon.add(bunny);

 

// Get Pet

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

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

 

// Count

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

 

// Get Statistics

System.out.println(salon.getStatistics());

// The grooming salon has the following clients:

//Bella Mia

//Zak Jon

Тагове:
0
Java Advanced
svephoto avatar svephoto 1191 Точки

Здравей, Olegati,

 

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

 

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

 

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

0
Olegati avatar Olegati 7 Точки

Благодаря!

0
svephoto avatar svephoto 1191 Точки

Моля.

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.