-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCity.cs
79 lines (64 loc) · 2.12 KB
/
City.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
using System;
namespace LabWork_10
{
public class City : Region
{
private Address copyAddress;
public Address CopyAddress
{
get => copyAddress;
set => copyAddress = value == null ? new Address() : value;
}
private int houses;
public int Houses
{
get => houses;
set
{
if (value >= 0) houses = value;
else houses = 0;
}
}
public City() : base("Город без имени") { } //base() - вызов конструктора базового класса
public City(string name, int population = 0, int houses = 0, Address copyAdr = null)
{
if (String.IsNullOrWhiteSpace(name)) name = "Город без имени";
Name = name;
Population = population;
Houses = houses;
CopyAddress = copyAdr;
}
public new void PrintInfo()
{
base.PrintInfo();
Console.WriteLine($"Количество домов: {Houses}");
}
public override void PrintInformation()
{
base.PrintInformation();
Console.WriteLine($"Количество домов: {Houses}");
}
public override string ToString()
{
return base.ToString() + $"\nДомов: {Houses}";
}
public new object Clone()
{
return new City(Name, Population, Houses, (Address)CopyAddress.Clone());
}
public new object ShallowCopy()
{
return (City)this.MemberwiseClone();
}
public new int CompareTo(object obj)
{
City temp = (City)obj;
if (String.Compare(temp.Name, this.Name) != 0) return String.Compare(temp.Name, this.Name);
if (temp.Population > this.Population) return 1;
if (temp.Population < this.Population) return -1;
if (temp.Houses > this.Houses) return 1;
if (temp.Houses < this.Houses) return -1;
return 0;
}
}
}