Моля за помощ какво пропускам -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}
(…)"
- "Rabbits available at {cageName}:
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) //Add Rabbit Console.WriteLine(cage.Count); //1 //Remove Rabbit Rabbit secondRabbit = new Rabbit("Bunny", "Brazilian"); //Add Rabbits //Sell Rabbit by name //Sell Rabbit by species Console.WriteLine(string.Join(", ", soldSpecies.Select(f => f.Name))); //Jumpy, Puffy Console.WriteLine(cage.Report()); |