Class Practice + Enum

 avatar
unknown
csharp
a year ago
7.1 kB
5
Indexable
internal class Program
{
    private static void Main()
    {
        Console.WriteLine("Hello World");

        Apartment[] apartments = new Apartment[]
        {
            new Apartment(
                "3-х комнатная в ЖК",
                "Kazakhstan, Atyrau",
                new Room[]
                {
                    new Room("Ванная", width: 100,height: 200, length: 300,
                        new Window[]
                        {
                            new Window(30, 20, Material.Plastic)
                        },
                        new Door[]
                        {
                            new Door(100, 300, Material.Wood),
                        }),
                    new Room("Спальня", width: 200,height: 100, length: 250,new Window[]
                        {
                            new Window(30, 20, Material.Plastic)
                        },
                        new Door[]
                        {
                            new Door(100, 300, Material.Plastic),
                        }),
                    new Room("Кухня", width: 325,height: 125, length: 100,
                        new Window[]
                        {
                            new Window(100, 100, Material.Plastic),
                            new Window(100, 100, Material.Plastic),
                        },
                        new Door[]
                        {
                            new Door(150, 350, Material.Plastic),
                        }),
                }),
            new Apartment(
                "4-х комнатная в ЖК",
                "Kazakhstan, Atyrau",
                new Room[]
                {
                    new Room("Ванная", width: 100,height: 200, length: 300,
                        new Window[]
                        {
                            new Window(30, 20, Material.Plastic)
                        },
                        new Door[] { new Door(100, 300, Material.Plastic) }),
                    new Room("Спальня", width: 200,height: 100, length: 250,
                        new Window[]
                        {
                            new Window(30, 20, Material.Plastic)
                        },
                        new Door[] { new Door(100, 300, Material.Plastic) }),
                    new Room("Кухня", width: 325,height: 125, length: 100,
                        new Window[]
                        {
                            new Window(30, 20, Material.Plastic)
                        },
                        new Door[] { new Door(100, 300, Material.Plastic) }),
                    new Room("Детская", width: 325,height: 125, length: 100,
                        new Window[]
                        {
                            new Window(30, 20, Material.Plastic)
                        },
                        new Door[] { new Door(100, 300, Material.Plastic) }),
                }),
    };

        while (true)
        {
            Console.Clear();

            Console.WriteLine();

            Console.WriteLine("Добро пожаловать!");
            Console.WriteLine("Выберите апартаменты: ");

            int index = 0;

            foreach (var apartment in apartments)
            {
                index++;
                Console.WriteLine($"{index}. {apartment.Name}");
            }

            int inputApartment = Convert.ToInt32(Console.ReadLine());

            if (inputApartment > 0 || inputApartment <= apartments.Length)
            {
                Console.Clear();

                Console.WriteLine($"Вы выбрали {apartments[inputApartment - 1].Name}");
                Console.WriteLine($"Местоположение: {apartments[inputApartment - 1].Location}");
                Console.WriteLine($"Количество комнат: {apartments[inputApartment - 1].Rooms.Length}");
                apartments[inputApartment - 1].ShowRooms();
                apartments[inputApartment - 1].ChoiceRoom();
            }
            else
            {
                Console.WriteLine("Неизвестный апартамент");
            }


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

/// 
/// ОКНА
/// Ширина
/// Высота
/// Материал
///
/// ///
/// 
/// ДВЕРЬ
/// Ширина
/// Высота
/// Материал
///

class Door
{
    public float Width;
    public float Height;
    public Material Material;

    public Door(float width, float height, Material material)
    {
        Width = width;
        Height = height;
        Material = material;
    }
}

class Window
{
    public float Width;
    public float Height;
    public Material Material;

    public Window(float width, float height, Material material)
    {
        Width = width;
        Height = height;
        Material = material;
    }
}

class Room
{
    public string Name;
    public float Width;
    public float Height;
    public float Length;
    public Window[] Windows;
    public Door[] Doors;

    public Room(string name, float width, float height, float length, Window[] windows, Door[] doors)
    {
        Width = width;
        Height = height;
        Length = length;
        Doors = doors;
        Windows = windows;
        Name = name;
    }

    public void ShowInfo()
    {
        Console.WriteLine();
        Console.WriteLine($"Комната: {Name}");
        Console.WriteLine($"Размеры (Ш,В,Д): {Width} см, {Height} см, {Length} см");
        Console.WriteLine($"Количество дверей: {Doors.Length}");
        Console.WriteLine($"Количество окон: {Windows.Length}");
    }

}

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()
    {
        Console.WriteLine();

        int index = 0;

        foreach (Room room in Rooms)
        {
            index++;

            Console.WriteLine($"{index}. {room.Name} [{(room.Length / 100) * (room.Width / 100)} кв.м.]");
        }
    }

    public void ChoiceRoom()
    {
        Console.WriteLine();
        Console.Write("Выберите комнату: ");

        int inputRoom = Convert.ToInt32(Console.ReadLine());

        if (inputRoom > 0 || inputRoom <= Rooms.Length)
        {
            Rooms[inputRoom - 1].ShowInfo();
        }
        else
        {
            Console.WriteLine("Неизвестная комната");
        }
    }
}

enum Material
{
    None,
    Plastic,
    Wood
}
Editor is loading...
Leave a Comment