Професионална програма
Loading...
+ Нов въпрос
Lypi_1003 avatar Lypi_1003 36 Точки

Guild Exam feb2020 66/100

Здравейте,

някой ако може да каже къде греша.

линк към изпита:

https://judge.softuni.bg/Contests/2032/CSharp-Advanced-Exam-22-Feb-2020

двата ми класа

https://pastebin.com/FtNa178G

https://pastebin.com/4mHWQaKA

 

Благодаря предварително

Тагове:
0
C# Advanced
DeathStar avatar DeathStar 11 Точки

Поствам моето решение тук (100/100):

Guid.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static Guild.StartUp;

namespace Guild
{
    public class Guild
    {
        List<Player> roster;
        public string Name { get; set; }
        public int Capacity { get; set; }

        public int Count => roster.Count;

        public Guild(string name, int capacity)
        {
            this.Name = name;
            this.Capacity = capacity;
            roster = new List<Player>();
        }

        public void AddPlayer(Player player)
        {
            if (this.Count < this.Capacity)
            {
                roster.Add(player);
            }
        }

        public bool RemovePlayer(string name)
        {
            var player = roster.FirstOrDefault(x => x.Name == name);
            return roster.Remove(player);
        }

        public void PromotePlayer(string name)
        {
            var player = roster.FirstOrDefault(x => x.Name == name);
            if (player != null)
            {
                if (player.Rank != "Member")
                {
                    roster[roster.IndexOf(player)].Rank = "Member";
                }
            }
        }

        public void DemotePlayer(string name)
        {
            var player = roster.FirstOrDefault(x => x.Name == name);
            if (player != null)
            {
                if (player.Rank != "Trial")
                {
                    roster[roster.IndexOf(player)].Rank = "Trial";
                }
            }
        }

        public Player[] KickPlayersByClass(string playerClass)
        {
            var temp = roster.Where(x => x.Class == playerClass).ToArray();
            roster = roster.Where(x => x.Class != playerClass).ToList();
            return temp;
        }

        public string Report()
        {
            string result = $"Players in the guild: {this.Name}";
            foreach (var item in roster)
            {
                result += Environment.NewLine + item.ToString();
            }
            return result;
        }
    }
}

 

 

Player.cs

 

using System;
using System.Collections.Generic;
using System.Text;

namespace Guild
{
    public class Player
    {
        public string Name { get; set; }
        public string Class { get; set; }
        public string Rank { get; set; }
        public string Description { get; set; }

        public Player(string name, string playerClass)
        {
            this.Name = name;
            this.Class = playerClass;
            this.Rank = "Trial";
            this.Description = "n/a";
        }

        public override string ToString()
        {
            return $"Player {this.Name}: {this.Class}{Environment.NewLine}Rank: {Rank}{Environment.NewLine}Description: {Description}";
        }
    }
}

0