-
Notifications
You must be signed in to change notification settings - Fork 5
/
Task4_Car
92 lines (87 loc) · 2.44 KB
/
Task4_Car
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
89
90
91
92
using System;
using System.Collections.Generic;
using System.Text;
namespace Task4
{
class Car
{
private string name;
private string color;
private double price;
const string CompanyName = "ZAZ";
public Car()
{ }
public Car(string name, string color, double price)
{
this.name = name;
this.color = color;
this.price = price;
}
public string Color
{
get { return color;}
set { color = value; }
}
public static Car Input()
{
Console.WriteLine("Enter car info: ");
Console.Write("\nEnter car name: ");
string name = Console.ReadLine();
Console.Write("\nEnter car color: ");
string color = Console.ReadLine();
Console.Write("\nEnter car price: ");
double price = int.Parse(Console.ReadLine());
Console.WriteLine();
Car car = new Car(name, color, price);
return car;
}
public void Print()
{
Console.WriteLine($"Name is {name}");
Console.WriteLine($"Color is {color}");
Console.WriteLine($"Price is {price}");
Console.WriteLine($"Company name is {CompanyName}");
Console.WriteLine();
}
public void ChangePrice(double x)
{
price -= price * x / 100;
}
public static void RePaint(Car[] cars, string color)
{
for (int i = 0; i < cars.Length; i++)
{
if (cars[i].color.ToLower() == "white")
{
cars[i].color = color;
}
}
}
public static bool operator ==(Car car1, Car car2)
{
if (car1.name == car2.name && car1.price == car2.price)
{
return true;
}
else
{
return false;
}
}
public static bool operator !=(Car car1, Car car2)
{
if (car1.name != car2.name && car1.price != car2.price)
{
return true;
}
else
{
return false;
}
}
public override string ToString()
{
return string.Format($"Name is {name}, Color is {color}, Price is {price}");
}
}
}