Class Practice
unknown
csharp
2 years ago
4.7 kB
17
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, 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),
}),
new Apartment(
"4-х комнатная в ЖК",
"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),
new Room("Детская", width: 325,height: 125, length: 100, doorCount: 2, windowCount: 0),
}),
};
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 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;
}
public void ShowInfo()
{
Console.WriteLine();
Console.WriteLine($"Комната: {Name}");
Console.WriteLine($"Размеры (Ш,В,Д): {Width} см, {Height} см, {Length} см");
Console.WriteLine($"Количество дверей: {DoorCount}");
Console.WriteLine($"Количество окон: {WindowCount}");
}
}
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("Неизвестная комната");
}
}
}
Editor is loading...
Leave a Comment