-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
72 lines (60 loc) · 1.83 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mod1_Lab2
{
class Program
{
static void Main(string[] args)
{
// Instantiating an object of Car() Class by using Type Inference called Car1
var Car1 = new Car();
// Using dot notation to call members on Car1
Car1.Color = "White";
Car1.Year = 2010;
Car1.Mileage = 11000;
var Car2 = new Car("red", 2008);
//Access static members
int carCount = Car.CountCars();
//output to the console window
Console.WriteLine($"There are {carCount} cars on inventory right now");
}
}
// Declaring the Car() Class
// This class has 3 properties: Color, Year, and Mileage
public class Car
{
// Defining properties
public string Color { get; set; }
public int Year { get; set; }
public int Mileage { get; set; }
//Create integer variable called "instance" and assigns value to 0
private static int instances = 0;
public Car(string color, int year)
{
this.Color = color;
this.Year = year;
//Every time the constructor runs, increment "isntances"
instances++;
}
public Car(int year, int mileage)
{
this.Year = year;
this.Mileage = mileage;
//Every time the constructor runs, increment "instances"
instances++;
}
public Car()
{
//everytime the constructor runs, increment "instances"
instances++;
}
//Declare static member
public static int CountCars()
{
return instances;
}
}
}