Loading...

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

FrauCules avatar FrauCules 1 Точки

Моля за помощ какво пропускам -66 от 100% - C# Advanced Exam - 26 October 2019 - 3. Rabbits

Моето решение: 
StartUp - https://pastebin.com/7eZbVR8r
class Rabbits - https://pastebin.com/Rgai1NxM
class Cagr - https://pastebin.com/H5CGePLv

  
Условие:
Your task is to create a repository which stores rabbit cages by creating the classes described below.
First, write a C# class Rabbit with the following properties:

  • Name: string
  • Species: string
  • Available: bool - true by default

The class constructor should receive name and species. Override the ToString() method in the following format:

"Rabbit ({species}): {name}"

Next, write a C# class Cage that has data (a collection which stores the entity Rabbit). All entities inside the repository have the same properties. Also, the Cage class should have those properties:

  • Name: string
  • Capacity: int

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

  • Field data - collection that holds added rabbits
  • Method Add(Rabbit rabbit) - adds an entity to the data if there is room for it
  • Method RemoveRabbit(string name) - removes a rabbit by given name, if such exists, and returns bool
  • Method RemoveSpecies(string species) - removes all rabbits by given species
  • Method SellRabbit(string name) - sell (set its Available property to false without removing it from the collection) the first rabbit with the given name, also return the rabbit
  • Method SellRabbitsBySpecies(string species) - sells (set their Available property to false without removing them from the collection) and returns all rabbits from that species as an array
  • Getter Count - returns the number of rabbits
  • Report() - returns a string in the following format, including only not sold rabbits
    • "Rabbits available at {cageName}:
      {Rabbit1}
      {Rabbit2}
      (…)
      "

Constraints

  • The names of the rabbits will be always unique.
  • You will always have a rabbit added before receiving methods manipulating the Cage’s rabbits.

Sample code usage

//Initialize the repository (Cage)
Cage cage = new Cage("Wildness", 20);
//Initialize entity
Rabbit rabbit = new Rabbit("Fluffy", "Blanc de Hotot");
//Print Rabbit
Console.WriteLine(rabbit); //Rabbit (Blanc de Hotot): Fluffy

//Add Rabbit
cage.Add(rabbit);

Console.WriteLine(cage.Count); //1

//Remove Rabbit
cage.RemoveRabbit("Rabbit Name"); //false

Rabbit secondRabbit = new Rabbit("Bunny", "Brazilian");
Rabbit thirdRabbit = new Rabbit("Jumpy", "Cashmere Lop");
Rabbit fourthRabbit = new Rabbit("Puffy", "Cashmere Lop");
Rabbit fifthRabbit = new Rabbit("Marlin", "Brazilian");

//Add Rabbits
cage.Add(secondRabbit);
cage.Add(thirdRabbit);
cage.Add(fourthRabbit);
cage.Add(fifthRabbit);

//Sell Rabbit by name
Console.WriteLine(cage.SellRabbit("Bunny")); //Rabbit (Brazilian): Bunny

//Sell Rabbit by species
Rabbit[] soldSpecies = cage.SellRabbitsBySpecies("Cashmere Lop");

Console.WriteLine(string.Join(", ", soldSpecies.Select(f => f.Name))); //Jumpy, Puffy

Console.WriteLine(cage.Report());
//Rabbits available at Wildness:
//Rabbit (Blanc de Hotot): Fluffy
//Rabbit (Brazilian): Marlin

Тагове:
0
Module: Java Advanced
FrauCules avatar FrauCules 1 Точки

Вече работи, благодаря на колегите о т ФБ, които помогнаха :)

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