Created
July 7, 2015 21:05
-
-
Save 200even/5169f979eebf2ce91594 to your computer and use it in GitHub Desktop.
Scott Week 2 Day 2 - Mechanic Shop
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Mechanic_Shop | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Truck scottsTruck = new Truck(); | |
scottsTruck.Make = "Ford"; | |
scottsTruck.Model = "F150"; | |
scottsTruck.GasType = GasType.diesel; | |
Truck mikesTruck = new Truck(); | |
mikesTruck.Make = "Chevy"; | |
mikesTruck.Model = "Silverado"; | |
mikesTruck.GasType = GasType.regular; | |
Sedan danielsSedan = new Sedan(); | |
danielsSedan.Make = "Mini Cooper"; | |
danielsSedan.Model = "Countryman S"; | |
danielsSedan.GasType = GasType.highPerformance; | |
Sedan brandonsSedan = new Sedan(); | |
brandonsSedan.Make = "Subaru"; | |
brandonsSedan.Model = "Legacy"; | |
brandonsSedan.GasType = GasType.regular; | |
RaceCar davidsRaceCar = new RaceCar(); | |
davidsRaceCar.Make = "Ferarri"; | |
davidsRaceCar.Model = "Enzo"; | |
davidsRaceCar.GasType = GasType.highPerformance; | |
RaceCar jasonsRaceCar = new RaceCar(); | |
jasonsRaceCar.Make = "Tesla"; | |
jasonsRaceCar.Model = "Roadster"; | |
jasonsRaceCar.GasType = GasType.electric; | |
Shop<Truck> TruckShop = new Shop<Truck>(); | |
TruckShop.ChangeOil(scottsTruck); | |
TruckShop.ChangeTires(scottsTruck); | |
TruckShop.ChangeOil(mikesTruck); | |
TruckShop.ChangeTires(mikesTruck); | |
TruckShop.FillUp(scottsTruck); | |
TruckShop.FillUp(mikesTruck); | |
Shop<Sedan> SedanShop = new Shop<Sedan>(); | |
SedanShop.ChangeOil(danielsSedan); | |
SedanShop.ChangeTires(danielsSedan); | |
SedanShop.ChangeOil(brandonsSedan); | |
SedanShop.ChangeTires(brandonsSedan); | |
SedanShop.FillUp(danielsSedan); | |
SedanShop.FillUp(brandonsSedan); | |
Shop<RaceCar> RaceShop = new Shop<RaceCar>(); | |
RaceShop.ChangeOil(davidsRaceCar); | |
RaceShop.FillUp(davidsRaceCar); | |
RaceShop.ChangeTires(jasonsRaceCar); | |
Console.ReadLine(); | |
} | |
} | |
public sealed class Shop<T> where T : IVehicle | |
{ | |
public void ChangeOil(T vehicle) | |
{ | |
Console.WriteLine("The oil has been changed on a {0}.", vehicle); | |
} | |
public void FillUp(T vehicle) | |
{ | |
Console.WriteLine("The {0} has been filled up with {1}.", vehicle, vehicle.GasType); | |
} | |
} | |
public static class ShopExtensions | |
{ | |
public static void ChangeTires<T>(this Shop<T> shop, IVehicle vehicle) where T : IVehicle | |
{ | |
Console.WriteLine("The tires have been changed on the {0}.", vehicle); | |
} | |
} | |
public class Truck : IVehicle | |
{ | |
public GasType GasType { get; set; } | |
public string Make { get; set; } | |
public string Model { get; set; } | |
public override string ToString() | |
{ | |
return Make + " " + Model + " truck"; | |
} | |
} | |
public class Sedan : IVehicle | |
{ | |
public GasType GasType { get; set; } | |
public string Make { get; set; } | |
public string Model { get; set; } | |
public override string ToString() | |
{ | |
return Make + " " + Model + " sedan"; | |
} | |
} | |
public class RaceCar : IVehicle | |
{ | |
public GasType GasType { get; set; } | |
public string Make { get; set; } | |
public string Model { get; set; } | |
public override string ToString() | |
{ | |
return Make + " " + Model + " racecar"; | |
} | |
} | |
public enum GasType | |
{ | |
electric = 3, | |
regular = 0, | |
highPerformance = 1, | |
diesel = 2 | |
} | |
public interface IVehicle | |
{ | |
string Make { get; set; } | |
string Model { get; set; } | |
GasType GasType { get; set; } | |
string ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment