-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nov2Car.cs
88 lines (81 loc) · 1.63 KB
/
Nov2Car.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
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Experements
{
public class Car
{
private static int count;
public static int Count { get => count;}
public String Mark { set; get; }
private int speed;
public bool IsCrushed { set; get; }
public int Speed
{
set
{
if (value >= 0) speed = value;
else throw new ArgumentException("Error value " + value);
}
get { return speed; }
}
private readonly int maxSpeed;
public int MaxSpeed { get { return maxSpeed; } }
public Car(string nm = "Unnamed", int sp = 93, int mx = 220)
{
Mark = nm;
Speed = sp;
maxSpeed = mx;
}
public override string ToString()
{
return Mark + "\t" + Speed + "\t" + MaxSpeed;
}
public void Accelerate(int d)
{
if (IsCrushed)
return;
this.Speed += d;
if (MaxSpeed <= Speed)
IsCrushed = true;
else if (Speed + 1 > MaxSpeed) { }
else
WriteLine(this);
}
public static bool operator >(Car c1, Car c2)
{
if (c1.MaxSpeed > c2.MaxSpeed)
return true;
return false;
}
public static bool operator <(Car c1, Car c2)
{
return !(c1>c2 &&c1 ==c2);
}
public override int GetHashCode()
{
return ToString().GetHashCode();
}
public override bool Equals(object obj)
{
if (obj is Car)
{
Car c1 =obj as Car;
if (c1.GetHashCode() == this.GetHashCode())
return true;
}
return false;
}
public static bool operator ==(Car c1,Car c2)
{
return c1.Equals(c2);
}
public static bool operator !=(Car c1,Car c2)
{
return !(c1 == c2);
}
}
}