Created
October 29, 2015 05:04
-
-
Save CasonBarnhill/2ef565ff046b90d3019a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace week_2_day_2.cs | |
{ | |
// Mechanic Shop | |
//We are going to design an application for a local mechanic shop. | |
//They service 3 types of vehicles: Trucks, Race Cars, and Family Sedans.All vehicles can have their tires and oil changed. | |
//When filling up gas for the vehicles, we have to be careful what type of gas we put in: Regular, High Performance, and Diesel. | |
//Create a 'Shop' class, using generics, that can handle these 3 types of cars. | |
//This 'Shop' class will perform the following functions: ChangeOil and FillUp() | |
//The 'ChangeTire' function should be tacked on using an extension method of the Shop Class. | |
//Demonstrate what your Shop Class can do by creating instances of all 3 car types, the shop and call the ChangeTire, FillUp, and ChangeOil functions for each type. | |
//Each function should briefly state what it is doing to the console. | |
public class Shop<T> where T : IVehicle | |
{ | |
public void ChangeOil(T vehicle) | |
{ | |
} | |
public void FillUp(T vehicle) | |
{ | |
switch (vehicle.GasType) | |
{ | |
case GasType.Regular: | |
break; | |
Console.WriteLine($""); | |
case GasType.HighPerformance: | |
break; | |
Console.WriteLine($""); | |
case GasType.Diesel: | |
Console.WriteLine($""); | |
break; | |
} | |
} | |
} | |
public static class ShopExtension | |
{ | |
public static void ChangeTire<T>(Shop<T> shop, T vehicle) where T : IVehicle | |
{ | |
Console.WriteLine($"The tires have been changed on {vehicle}"); | |
} | |
} | |
public interface IVehicle | |
{ | |
GasType GasType { get; } | |
} | |
class Truck : IVehicle | |
{ | |
public GasType GasType { get { return GasType.Diesel; } } | |
public bool ChangedTire { get; set; } | |
public bool isOilChanged { get; set; } | |
public string F150 { get; private set ; } | |
public Truck(string carName) //<-----//my constructor | |
{ | |
this.F150 = carName; | |
} | |
public override string ToString() | |
{ | |
return this.F150; | |
} | |
} | |
class RaceCar : IVehicle | |
{ | |
public GasType GasType { get { return GasType.HighPerformance; } } | |
public bool ChangedTire { get; set; } | |
public bool isOilChanged { get; set; } | |
public string Sprint { get; private set; } | |
public RaceCar(string carName) //<-----//my constructor | |
{ | |
this.Sprint = carName; | |
} | |
public override string ToString() //<-----//override for my constructor above | |
{ | |
return this.Sprint; | |
} | |
} | |
class FamilySedan : IVehicle | |
{ | |
public GasType GasType { get { return GasType.Regular; } } | |
public bool ChangedTire { get; set; } | |
public bool isOilChanged { get; set; } | |
public string Altima { get; private set; } | |
public FamilySedan(string carName) //<-----//my constructor | |
{ | |
this.Altima = carName; | |
} | |
public override string ToString() //<-----//override for my constructor above | |
{ | |
return this.Altima; | |
} | |
} | |
public enum GasType | |
{ | |
Regular, | |
HighPerformance, | |
Diesel | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Shop<Truck> shop = new Shop<Truck>(); | |
Shop<RaceCar> shop1 = new Shop<RaceCar>(); | |
Shop<FamilySedan> shop2 = new Shop<FamilySedan>(); | |
Truck F150 = new Truck("F150"); | |
FamilySedan Altima = new FamilySedan("Altima"); | |
RaceCar Sprint = new RaceCar("Sprint"); | |
shop.ChangeOil(F150); | |
//shop.FillUp(Altima); | |
// shop.ChangeTire(Sprint); | |
Console.WriteLine($"Changed oil in {F150}"); | |
Console.WriteLine($"Changed Tires on {Sprint}"); | |
Console.WriteLine($"Filled up the gas on {Altima}"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment