Loading...
CvetelinP avatar CvetelinP -2 Точки

C# Advanced Exam - 26 October 2019 Rabbits

Може ли едно решение на задача 3.Rabbits от C# Advanced Exam - 26 October 2019 Rabbits

.....................

Preparation

Download the skeleton provided in Judge. Do not change the StartUp class or its namespace.

Problem description

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.

Examples

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

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

Submission

Zip all the files in the project folder except for the bin and obj folders

Тагове:
0
C# Advanced
SagoqFnewo avatar SagoqFnewo 1 Точки

An advanced exam is launched for the mid of the questions and answers for the field. All the tenets of the exam and https://ca.bestessays.com/ are visited for the answers. All the tips for the exams are passed down to the students for success.

0
sophienike avatar sophienike 0 Точки

I have a questionnaire on csharp provided by my software professor. I am looking for the masters dissertation writing help to solve that paper. Also, we have to create a Web based E-ERP business solution as our final year project. A web based ERP involves locating the system off-site and accessing it over a network with the help of a web browser. If someone here could guide me through the process, it would be much appreciated.

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