Загрузка данных


using System;

class Achievement
{
    public string Name { get; set; }
    public int Points { get; set; }

    public Achievement(string name, int points)
    {
        Name = name;
        Points = points;
    }

    public virtual void Show()
    {
        Console.WriteLine($"Достижение: {Name}, Очки: {Points}");
    }
}

class TimedAchievement : Achievement
{
    public int Minutes { get; set; }
    public int RemainingMinutes { get; set; }

    public TimedAchievement(string name, int points, int minutes, int remainingMinutes)
        : base(name, points)
    {
        Minutes = minutes;
        RemainingMinutes = remainingMinutes;
    }

    public override void Show()
    {
        Console.WriteLine($"Временное достижение: {Name}, Очки: {Points}, Минут: {Minutes}, Осталось: {RemainingMinutes}");
        if (RemainingMinutes <= 0)
            Console.WriteLine("Время вышло!");
        else
            Console.WriteLine("Время ещё есть.");
    }
}

class BuildRun
{
    public string ProjectName { get; set; }
    public int BuildNumber { get; set; }

    public BuildRun(string projectName, int buildNumber)
    {
        ProjectName = projectName;
        BuildNumber = buildNumber;
    }

    public string GetCode()
    {
        return $"{ProjectName}-{BuildNumber}";
    }
}

class TestBuildRun : BuildRun
{
    public int TotalTests { get; set; }
    public int PassedTests { get; set; }

    public TestBuildRun(string projectName, int buildNumber, int totalTests, int passedTests)
        : base(projectName, buildNumber)
    {
        TotalTests = totalTests;
        PassedTests = passedTests;
    }

    public double GetPassPercent()
    {
        if (TotalTests == 0) return 0;
        return (double)PassedTests / TotalTests * 100;
    }
}

class Quest
{
    private int progress;

    public string Name { get; set; }

    public int Progress
    {
        get { return progress; }
    }

    public Quest(string name)
    {
        Name = name;
        progress = 0;
    }

    protected void SetProgress(int value)
    {
        if (value < 0) value = 0;
        if (value > 100) value = 100;
        progress = value;
    }

    public void RegisterCheckpoint()
    {
        SetProgress(progress + 10);
    }
}

class TimedQuest : Quest
{
    public int TimeLimit { get; set; }
    public int ElapsedTime { get; set; }

    public TimedQuest(string name, int timeLimit, int elapsedTime)
        : base(name)
    {
        TimeLimit = timeLimit;
        ElapsedTime = elapsedTime;
    }

    public void RegisterCheckpoint()
    {
        if (ElapsedTime <= TimeLimit)
        {
            SetProgress(Progress + 10);
            Console.WriteLine("Контрольная точка зарегистрирована.");
        }
        else
        {
            Console.WriteLine("Лимит времени превышен, прогресс не изменён.");
        }
    }
}

class DigitalPass
{
    public string OwnerId { get; set; }
    public int AccessZone { get; set; }

    public DigitalPass(string ownerId, int accessZone)
    {
        if (string.IsNullOrWhiteSpace(ownerId))
            throw new ArgumentException("Идентификатор владельца не может быть пустым.");
        if (accessZone <= 0)
            throw new ArgumentException("Зона доступа должна быть положительным целым числом.");
        OwnerId = ownerId;
        AccessZone = accessZone;
    }
}

class TemporaryPass : DigitalPass
{
    public int DurationMinutes { get; set; }

    public TemporaryPass(string ownerId, int accessZone, int durationMinutes)
        : base(ownerId, accessZone)
    {
        if (durationMinutes <= 0)
            throw new ArgumentException("Срок действия должен быть больше нуля.");
        DurationMinutes = durationMinutes;
    }

    public void ShowInfo()
    {
        Console.WriteLine($"Временный пропуск: Владелец={OwnerId}, Зона={AccessZone}, Срок={DurationMinutes} мин.");
    }
}

class Notification
{
    public string Text { get; set; }
    public int Priority { get; set; }

    public Notification(string text, int priority)
    {
        if (priority < 1 || priority > 5)
            throw new ArgumentException("Приоритет должен быть от 1 до 5.");
        Text = text;
        Priority = priority;
    }

    public string GetShortLabel()
    {
        return $"[{Priority}] {Text}";
    }

    public virtual void Show()
    {
        Console.WriteLine(GetShortLabel());
    }
}

class SecurityNotification : Notification
{
    public int ThreatLevel { get; set; }
    public bool RequiresImmediateReaction { get; set; }

    public SecurityNotification(string text, int priority, int threatLevel)
        : base(text, priority)
    {
        ThreatLevel = threatLevel;
        RequiresImmediateReaction = threatLevel >= 4;
    }

    public override void Show()
    {
        Console.WriteLine($"{GetShortLabel()} | Уровень угрозы: {ThreatLevel} | Немедленная реакция: {(RequiresImmediateReaction ? "Да" : "Нет")}");
    }
}

class UpdateNotification : Notification
{
    public string Version { get; set; }
    public bool CanBePostponed { get; set; }

    public UpdateNotification(string text, int priority, string version, bool canBePostponed)
        : base(text, priority)
    {
        Version = version;
        CanBePostponed = canBePostponed;
    }

    public override void Show()
    {
        Console.WriteLine($"{GetShortLabel()} | Версия: {Version} | Можно отложить: {(CanBePostponed ? "Да" : "Нет")}");
    }
}

class TestRun
{
    public string ScenarioName { get; set; }
    public int Duration { get; set; }

    public TestRun(string scenarioName, int duration)
    {
        ScenarioName = scenarioName;
        Duration = duration;
    }
}

class AutomatedTestRun : TestRun
{
    public int TestCases { get; set; }
    public int SuccessfulTests { get; set; }

    public AutomatedTestRun(string scenarioName, int duration, int testCases, int successfulTests)
        : base(scenarioName, duration)
    {
        TestCases = testCases;
        SuccessfulTests = successfulTests;
    }

    public double GetSuccessPercent()
    {
        if (TestCases == 0) return 0;
        return (double)SuccessfulTests / TestCases * 100;
    }
}

class LoadTestRun : AutomatedTestRun
{
    public int RequestsPerSecond { get; set; }
    public int MaxResponseTime { get; set; }

    public LoadTestRun(string scenarioName, int duration, int testCases, int successfulTests, int requestsPerSecond, int maxResponseTime)
        : base(scenarioName, duration, testCases, successfulTests)
    {
        RequestsPerSecond = requestsPerSecond;
        MaxResponseTime = maxResponseTime;
    }

    public bool MeetsRequirements(int minRps, int maxResponseTimeLimit)
    {
        return RequestsPerSecond >= minRps && MaxResponseTime <= maxResponseTimeLimit;
    }
}

class BackupTask
{
    public string Name { get; set; }
    public int TotalDataMB { get; set; }

    public BackupTask(string name, int totalDataMB)
    {
        Name = name;
        TotalDataMB = totalDataMB;
    }

    public int GetRemainingMB(int processedMB)
    {
        return TotalDataMB - processedMB;
    }
}

class BackupSchedule
{
    public int StartHour { get; set; }
    public int IntervalDays { get; set; }

    public BackupSchedule(int startHour, int intervalDays)
    {
        StartHour = startHour;
        IntervalDays = intervalDays;
    }
}

class SecureBackupTask : BackupTask
{
    public int EncryptionLevel { get; set; }

    public SecureBackupTask(string name, int totalDataMB, int encryptionLevel)
        : base(name, totalDataMB)
    {
        EncryptionLevel = encryptionLevel;
    }

    public void Encrypt()
    {
        Console.WriteLine($"Шифрование с уровнем {EncryptionLevel} выполнено.");
    }
}

class ReleaseArtifact
{
    public string Id { get; set; }
    public string Version { get; set; }
    public double SizeMB { get; set; }

    public ReleaseArtifact(string id, string version, double sizeMB)
    {
        if (string.IsNullOrWhiteSpace(id))
            throw new ArgumentException("Идентификатор обязателен.");
        if (string.IsNullOrWhiteSpace(version))
            throw new ArgumentException("Версия обязательна.");
        if (sizeMB <= 0)
            throw new ArgumentException("Размер должен быть положительным.");
        Id = id;
        Version = version;
        SizeMB = sizeMB;
    }

    public double GetTransferTime(double speedMbps)
    {
        if (speedMbps <= 0) return 0;
        return SizeMB / speedMbps;
    }
}

class InstallerPackage : ReleaseArtifact
{
    public string Platform { get; set; }
    public double RequiredFreeSpaceMB { get; set; }
    public bool IsSigned { get; set; }

    public InstallerPackage(string id, string version, double sizeMB, string platform, double requiredFreeSpaceMB, bool isSigned)
        : base(id, version, sizeMB)
    {
        Platform = platform;
        RequiredFreeSpaceMB = requiredFreeSpaceMB;
        IsSigned = isSigned;
    }

    public bool CanInstall(double freeSpaceMB)
    {
        return freeSpaceMB >= RequiredFreeSpaceMB && IsSigned;
    }
}

class UpdatePackage : ReleaseArtifact
{
    public string TargetVersion { get; set; }
    public int ChangedFiles { get; set; }

    public UpdatePackage(string id, string version, double sizeMB, string targetVersion, int changedFiles)
        : base(id, version, sizeMB)
    {
        TargetVersion = targetVersion;
        ChangedFiles = changedFiles;
    }

    public bool IsSmallUpdate(int threshold)
    {
        return ChangedFiles <= threshold;
    }
}

class RaceVehicle
{
    public string Name { get; set; }
    public int MaxSpeed { get; set; }
    protected int CurrentSpeed;
    protected bool IsMoving;

    public RaceVehicle(string name, int maxSpeed)
    {
        Name = name;
        MaxSpeed = maxSpeed;
        CurrentSpeed = 0;
        IsMoving = false;
    }

    public void Start()
    {
        IsMoving = true;
        Console.WriteLine($"{Name} начал движение.");
    }

    public void Accelerate(int value)
    {
        if (!IsMoving)
        {
            Console.WriteLine("Транспорт не движется.");
            return;
        }
        CurrentSpeed += value;
        if (CurrentSpeed > MaxSpeed) CurrentSpeed = MaxSpeed;
        Console.WriteLine($"{Name} ускорился до {CurrentSpeed} км/ч.");
    }

    public void Brake(int value)
    {
        if (!IsMoving)
        {
            Console.WriteLine("Транспорт не движется.");
            return;
        }
        CurrentSpeed -= value;
        if (CurrentSpeed < 0) CurrentSpeed = 0;
        Console.WriteLine($"{Name} замедлился до {CurrentSpeed} км/ч.");
    }

    public void Stop()
    {
        IsMoving = false;
        CurrentSpeed = 0;
        Console.WriteLine($"{Name} остановлен.");
    }

    public void ShowStatus()
    {
        Console.WriteLine($"{Name}: {CurrentSpeed} / {MaxSpeed}");
    }
}

class Car : RaceVehicle
{
    public int Fuel { get; set; }

    public Car(string name, int maxSpeed, int fuel)
        : base(name, maxSpeed)
    {
        Fuel = fuel;
    }

    public void Refuel(int amount)
    {
        Fuel += amount;
        Console.WriteLine($"{Name} заправлен. Топливо: {Fuel}");
    }

    public new void Start()
    {
        if (Fuel <= 0)
        {
            Console.WriteLine("Недостаточно топлива!");
            return;
        }
        base.Start();
    }
}

class Motorcycle : RaceVehicle
{
    public bool HasSidecar { get; set; }

    public Motorcycle(string name, int maxSpeed, bool hasSidecar)
        : base(name, maxSpeed)
    {
        HasSidecar = hasSidecar;
    }

    public void Wheelie()
    {
        if (IsMoving)
            Console.WriteLine($"{Name} делает вилли!");
        else
            Console.WriteLine("Сначала начните движение.");
    }
}

class Truck : RaceVehicle
{
    public int CargoWeight { get; set; }

    public Truck(string name, int maxSpeed, int cargoWeight)
        : base(name, maxSpeed)
    {
        CargoWeight = cargoWeight;
    }

    public void LoadCargo(int weight)
    {
        CargoWeight += weight;
        Console.WriteLine($"{Name} загружен. Вес груза: {CargoWeight}");
    }
}

class Program
{
    static void Main()
    {
        Console.WriteLine("=== Задание 1 ===");
        var ach1 = new Achievement("Первые шаги", 10);
        var ach2 = new TimedAchievement("Скоростной", 50, 30, 15);
        ach1.Show();
        ach2.Show();

        Console.WriteLine("\n=== Задание 2 ===");
        var run1 = new BuildRun("MyProject", 42);
        var run2 = new TestBuildRun("MyProject", 43, 100, 85);
        Console.WriteLine(run1.GetCode());
        Console.WriteLine(run2.GetCode());
        Console.WriteLine($"Процент успешных тестов: {run2.GetPassPercent()}%");

        Console.WriteLine("\n=== Задание 3 ===");
        var quest = new TimedQuest("Найти артефакт", 60, 45);
        quest.RegisterCheckpoint();
        Console.WriteLine($"Прогресс: {quest.Progress}");

        Console.WriteLine("\n=== Задание 4 ===");
        var pass1 = new TemporaryPass("user1", 3, 120);
        var pass2 = new TemporaryPass("user2", 5, 60);
        pass1.ShowInfo();
        pass2.ShowInfo();

        Console.WriteLine("\n=== Задание 5 ===");
        var sec = new SecurityNotification("Взлом", 5, 5);
        var upd = new UpdateNotification("Обновление", 3, "1.2.3", true);
        sec.Show();
        upd.Show();

        Console.WriteLine("\n=== Задание 6 ===");
        var load = new LoadTestRun("Нагрузочный", 120, 200, 180, 500, 200);
        Console.WriteLine($"Успешных: {load.GetSuccessPercent()}%");
        Console.WriteLine($"Соответствует требованиям: {load.MeetsRequirements(400, 250)}");

        Console.WriteLine("\n=== Задание 7 ===");
        var task = new BackupTask("Бэкап", 1000);
        var schedule = new BackupSchedule(2, 7);
        var secure = new SecureBackupTask("Защищённый бэкап", 2000, 3);
        Console.WriteLine($"Осталось: {task.GetRemainingMB(300)} МБ");
        Console.WriteLine($"Расписание: {schedule.StartHour}:00 каждые {schedule.IntervalDays} дней");
        secure.Encrypt();

        Console.WriteLine("\n=== Задание 8 ===");
        var installer1 = new InstallerPackage("inst1", "1.0", 500, "Windows", 200, true);
        var installer2 = new InstallerPackage("inst2", "1.1", 600, "Linux", 300, false);
        var update1 = new UpdatePackage("upd1", "2.0", 150, "1.9", 10);
        var update2 = new UpdatePackage("upd2", "2.1", 200, "2.0", 50);
        Console.WriteLine($"Установка возможна: {installer1.CanInstall(250)}");
        Console.WriteLine($"Установка возможна: {installer2.CanInstall(350)}");
        Console.WriteLine($"Малое обновление: {update1.IsSmallUpdate(20)}");
        Console.WriteLine($"Малое обновление: {update2.IsSmallUpdate(20)}");

        Console.WriteLine("\n=== Задание 9 ===");
        bool race = true;
        var car = new Car("Гонщик", 200, 50);
        while (race)
        {
            Console.WriteLine("1 - начать, 2 - ускорить, 3 - замедлить, 4 - статус, 5 - финиш");
            string choice = Console.ReadLine();
            switch (choice)
            {
                case "1": car.Start(); break;
                case "2": car.Accelerate(20); break;
                case "3": car.Brake(10); break;
                case "4": car.ShowStatus(); break;
                case "5": race = false; break;
            }
        }
    }
}