Created
August 26, 2012 06:21
-
-
Save smallgeek/3474969 to your computer and use it in GitHub Desktop.
NaturalSpec_Tutorial_3_4
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 CarSellingLib | |
{ | |
public enum CarType | |
{ | |
Fiat, | |
BMW | |
} | |
} | |
namespace CarSellingLib | |
{ | |
public class Car | |
{ | |
public Car(CarType type, int horsePower) | |
{ | |
Type = type; | |
HorsePower = horsePower; | |
} | |
public CarType Type { get; set; } | |
public int HorsePower { get; set; } | |
# region ToString, Equals | |
public override string ToString() | |
{ | |
return string.Format("{0} ({1} HP)", Type, HorsePower); | |
} | |
public override bool Equals(object obj) | |
{ | |
var y = obj as Car; | |
if(y == null) return false; | |
return Type == y.Type && HorsePower == y.HorsePower; | |
} | |
#endregion | |
} | |
} | |
using System; | |
namespace CarSellingLib | |
{ | |
public class Dealer | |
{ | |
public Dealer(string name) | |
{ | |
Name = name; | |
} | |
public string Name { get; set; } | |
public Car SellCar(int amount) | |
{ | |
if (amount > 20000) | |
return new Car(CarType.BMW, 200); | |
if (amount > 3000) | |
return new Car(CarType.Fiat, 45); | |
throw new Exception("Need more money"); | |
} | |
public override string ToString() | |
{ | |
return Name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment