-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (76 loc) · 2.59 KB
/
Program.cs
File metadata and controls
100 lines (76 loc) · 2.59 KB
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
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
namespace OOP3
{
public class Program {
public static void Main(String[] args)
{
CarLot CL1 = new CarLot("Chase's Cars");
CarLot CL2 = new CarLot("Other guys' Cars");
Car mazda = new Car("White", "Mazda", "3", "Hatchback");
Car subaru = new Car("Black", "Subaru", "Impreza", "Sedan");
Car chevy = new Car("Silver", "Chevy", "Malibu", "Sedan");
Car toyota = new Car("Green", "Toyota", "Celica", "Coupe");
Truck f150 = new Truck("Red", "Ford", "F-150", 5);
Truck titan = new Truck("Gray","Nissan","Titan", 5);
Truck ram = new Truck("Black", "Dodge", "Ram", 6);
CL1.Add(mazda);
CL1.Add(subaru);
CL1.Add(f150);
CL2.Add(toyota);
CL2.Add(titan);
CL2.Add(ram);
CL1.PrintInventory();
CL2.PrintInventory();
}
}
public class CarLot {
List<Vehicle> inventory;
String name;
public CarLot(string intialName){
this.name = intialName;
}
public void Add(Vehicle vehicle){
inventory.Add(vehicle);
}
public void PrintInventory(){
foreach(var vehicle in inventory){
Console.WriteLine(vehicle.ToString());
}
}
}
public abstract class Vehicle {
string color;
string make;
string model;
public Vehicle(string intialColor, string intialMake, string intialModel){
this.color = intialColor;
this.make = intialMake;
this.model = intialModel;
}
override
public String ToString(){
String s1 = string.Format(this.color + "" + this.make + "" + this.model + "");
return s1;
}
}
public class Car : Vehicle{
string bodyType;
public Car(string initialColor, string initialMake, string intialModel, string intialBodyType) :
base(initialColor, initialMake, intialModel ){
this.bodyType = intialBodyType;
}
override
public String ToString(){
String s2 = string.Format(this.bodyType);
return s2;
}
}
public class Truck : Vehicle {
int cabSize;
public Truck(string intialColor, string initialMake, string intialModel, int initialCabSize) :
base(intialColor, initialMake, intialModel){
this.cabSize = initialCabSize;
}
}
}