Loading...

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

arnold avatar arnold 50 Точки

Guild (C# Defining classes)

 

Колеги малко помощ с тази задача, стигам до 91/100, не мога да си намеря грешката и какво пропускам?

 

За да не търся начин да пращам зип файл, тъй като и проектът си е доста малък, всеки клас е в отделен пейстбин, както и мейн методът. Трябва само да се копират като преди това трябва да се създадат двата класа Player и Guild, всички други изисиквания за judge са настроени.

 

Class Player : https://pastebin.com/UPN4q1Sd

 

Class Guild: https://pastebin.com/TzXBPbhF

 

Main:  https://pastebin.com/WeCgAMWh

 

https://judge.softuni.org/Contests/Practice/Index/2032#2

 

 

 

Guild

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 players by creating the classes described below.

First, write a C# class Player with the following properties:

  • Name: string
  • Class: string
  • Rank: string – "Trial" by default
  • Description: string – "n/a" by default

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

"Player {Name}: {Class}

Rank: {Rank}

Description: {Description}"

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

  • Name: string
  • Capacity: int

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

  • Field roster - collection that holds added players
  • Method AddPlayer(Player player) - adds an entity to the roster if there is room for it
  • Method RemovePlayer(string name) - removes a player by given name, if such exists, and returns bool
  • Method PromotePlayer(string name) - promote (set his rank to "Member") the first player with the given name. If the player is already a "Member", do nothing.
  • Method DemotePlayer(string name)- demote (set his rank to "Trial") the first player with the given name. If the player is already a "Trial",  do nothing.
  • Method KickPlayersByClass(string class) - removes all the players by the given class and returns all players from that class as an array
  • Getter Count - returns the number of players
  • Report() - returns a string in the following format:             
    • "Players in the guild: {guildName}
      {Player1}
      {Player2}
      (…)
      "

Constraints

  • The names of the players will be always unique.
  • You will always have a player added before receiving methods manipulating the Guild's players.

Examples

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

Sample code usage

//Initialize the repository (guild)

Guild guild = new Guild("Weekend Raiders", 20);

//Initialize entity

Player player = new Player("Mark", "Rogue");

//Print player

Console.WriteLine(player); //Player Mark: Rogue

                           //Rank: Trial

                           //Description: n/a

 

//Add player

guild.AddPlayer(player);

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

Console.WriteLine(guild.RemovePlayer("Gosho")); //False

 

Player firstPlayer = new Player("Pep", "Warrior");

Player secondPlayer = new Player("Lizzy", "Priest");

Player thirdPlayer = new Player("Mike", "Rogue");

Player fourthPlayer = new Player("Marlin", "Mage");

 

//Add description to player

secondPlayer.Description = "Best healer EU";

 

//Add players

guild.AddPlayer(firstPlayer);

guild.AddPlayer(secondPlayer);

guild.AddPlayer(thirdPlayer);

guild.AddPlayer(fourthPlayer);

 

//Promote player

guild.PromotePlayer("Lizzy");

 

//RemovePlayer

Console.WriteLine(guild.RemovePlayer("Pep")); //True

 

Player[] kickedPlayers = guild.KickPlayersByClass("Rogue");

Console.WriteLine(string.Join(", ", kickedPlayers.Select(p => p.Name))); //Mark, Mike

 

Console.WriteLine(guild.Report());

//Players in the guild: Weekend Raiders

//Player Lizzy: Priest

//Rank: Member

//Description: Best healer EU

//Player Marlin: Mage

//Rank: Trial

//Description: n/a

Submission

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

 

Тагове:
1
Module: C# Advanced 21/10/2021 21:31:27
Axiomatik avatar Axiomatik 2422 Точки
Best Answer
        public void AddPlayer(Player player)
        {
            // if (roster.Count <= Capacity)
            if (roster.Count < Capacity)
            {
                roster.Add(player);
            }
        }

 

Method AddPlayer(Player player) - adds an entity to the roster if there is room for it.

When roster.Count <= Capacity, will still add player when Count has reached capacity,

 

Hope this gets last test !

1
arnold avatar arnold 50 Точки

Благодаря много! 

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