-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
80 lines (65 loc) · 1.62 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
namespace PracticalWorkClasses1OAiP;
public class Program
{
public static void Main(string[] args)
{
Car car = new("Лада", 2008);
car.DisplayInfo();
Book book = new("Пикник на обочине", "Стругацкие");
book.DisplayInfo();
Rectangle rectangle = new(2, 5);
rectangle.DisplayArea();
}
}
public class Car
{
public string? Make;
public int Year;
public Car(string? make, int year)
{
Make = make;
Year = year;
}
public void DisplayInfo() => Console.WriteLine(
$"Марка машины: {Make}\n" +
$"Год выкуска: {Year}\n\n");
}
public class Book
{
private string? _title;
private string? _author;
public string? Title => _title;
public string? Author => _author;
public Book(string? title, string? author)
{
_title = title;
_author = author;
}
public void DisplayInfo() => Console.WriteLine(
$"Название книги: {_title}\n" +
$"Автор: {_author}\n\n");
}
public class Rectangle()
{
private float _width;
private float _height;
public Rectangle(float width, float height) : this()
{
Width = width;
Height = height;
}
public float Width
{
get => _width;
set => _width = value <= .0f ? 1f : value;
}
public float Height
{
get => _height;
set => _height = value <= .0f ? 1f : value;
}
public void DisplayArea()
{
Console.WriteLine($"Площадь прямоугольника: {_width * _height}");
}
}