Class Practice #SomeIndex

mail@pastecode.io avatar
unknown
csharp
a month ago
2.5 kB
20
Indexable
Never
internal class Program
{
    private static void Main()
    {
        Console.WriteLine("Hello World");

        Apartment apartment1 = new Apartment(
            "3-х комнатная в ЖК",
            "Kazakhstan, Atyrau",
            new Room[]
            {
                new Room("Ванная", width: 100,height: 200, length: 300, doorCount: 1, windowCount: 2),
                new Room("Спальня", width: 200,height: 100, length: 250, doorCount: 1, windowCount: 1),
                new Room("Кухня", width: 325,height: 125, length: 100, doorCount: 2, windowCount: 0),
            });

        while (true)
        {
            Console.WriteLine("Добро пожаловать!");
            Console.WriteLine("Выберите апартаменты: ");
            Console.WriteLine($"1. {apartment1.Name}");

            switch (Convert.ToInt32(Console.ReadLine()))
            {
                case 1:
                    Console.WriteLine($"Вы выбрали {apartment1.Name}");
                    Console.WriteLine($"Местоположение: {apartment1.Location}");
                    Console.WriteLine($"Количество комнат: {apartment1.Rooms.Length}");
                    apartment1.ShowRooms();
                    break;
                default:
                    Console.WriteLine("Неизвестная команда");
                    break;
            }

            Console.WriteLine("Для продолжения нажмите любую клавишу");
            Console.ReadKey();
        }
    }
}

/// 

class Room
{
    public string Name;
    public float Width;
    public float Height;
    public float Length;
    public int DoorCount;
    public int WindowCount;

    public Room(string name, float width, float height, float length, int doorCount, int windowCount)
    {
        Width = width;
        Height = height;
        Length = length;
        DoorCount = doorCount;
        WindowCount = windowCount;
        Name = name;
    }
}

class Apartment
{
    public string Name;
    public string Location;
    public Room[] Rooms;

    public Apartment(string name, string location, Room[] rooms)
    {
        Name = name;
        Location = location;
        Rooms = rooms;
    }

    public void ShowRooms()
    {
        foreach (Room room in Rooms)
        {
            Console.WriteLine(room.Name);
        }
    }
}
Leave a Comment