namespace public int BushelsToFeed { get; set; } ///

namespace Hammurabi{    public class Kingdom    {        public const string NotALegalNumber =            “Hamurabi:  Let’s try to think in whole numbers here.”;        private const string NotEnoughBushels =            “Hamurabi:  Think again.  You have only
{0} bushels of grain. Now then,
“;        private const string NotEnoughAcres =            “Hamurabi:  Think again.  You have only
{0} acres. Now then,
“;        private const string NotEnoughPeople =            “But you have only {0} people to tend the fields.
“;        public const int YearsOfRule = 10;        private readonly Random _rnd = new Random();        public int LandPrice { get; set; }        public int RatLossLastYear { get; set; }        public int DeathsLastYear { get; set; }        public int ImmigrantsLastYear { get; set; }        public int YeildLastYear { get; set; }        public bool PlagueLastYear { get; set; }        public int AcresPlantedLastYear { get; set; }        public double PODAK { get; set; } // Percentage of deaths attributable to the King.         public int TotalStarvations { get; set; }        public int People { get; set; }        public int Acres { get; set; }        public int Bushels { get; set; }        public int Year { get; set; }        public int BushelsToFeed { get; set; }        ///

        /// Initializes a new instance of the class.        ///

        public Kingdom()        {            LandPrice = GetNewLandPrice();            DeathsLastYear = 0;            PODAK = 0;            ImmigrantsLastYear = 5;            People = 100;            Acres = 1000;            Year = 1;            RatLossLastYear = 200;            Bushels = 2800;            YeildLastYear = 3;        }        public string GetReport()        {            string report = string.Empty;            if (PlagueLastYear)            {                report += ”
A horrible plage struck! Half the people died.
“;            }            else            {                report += ”
Hakmurabi: I beg to report to you,
“;                report += “in year {0}, {1} people starved, {2} came to the city,
“;            }            report += “Population is now {3}
“;            report += “The city now owns {4} acres.
“;            report += “You harvested {5} bushels per acre.
“;            report += “Rats ate {6} bushels.
“;            report += “You now have {7} bushels in store.
“;            report = String.Format(report, Year, DeathsLastYear, ImmigrantsLastYear,                People,                Acres,                YeildLastYear,                RatLossLastYear,                Bushels);            return report;        }        public string EndOfReignReport()        {            string report = string.Empty;            if (Impeachable())            {                report += ”
You starved {0} people in one year!!!
“;                report += “Due to this extreme mismanagement you have not only
“;                report += “been impeached and thrown out of office but you have
“;                report += “also been declared a national fink!!!!”;                report = String.Format(report, DeathsLastYear);                return report;            }            report += ”
In your {3}-year term of office, {0:N2} percent of the
“;            report += “population starved per year on average, i.e. a total of
“;            report += “{1} people died!!
“;            report += “You started with 10 acres per person and ended with
“;            report += “{2:N2} acres per person.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

“;            var p1 = PODAK / YearsOfRule;            var l = (double)Acres / People;            report = String.Format(report, p1, TotalStarvations, l, YearsOfRule);            if (p1 > 33 || l < 7)            {                report += "Due to this extreme mismanagement you have not only ";                report += "been impeached and thrown out of office but you have ";                report += "also been declared a national fink!!!!";            }            else if (p1 > 10 || l < 9)            {                report += "Your heavy-handed performance smacks of Nero and Ivan IV. ";                report += "The people (remaining) find you an unpleasant ruler, and, ";                report += "frankly, hate your guts!!";            }            else if (p1 > 3 || l < 10)            {                report += "Your performance could have been somewhat better, but ";                report += "really wasn't too bad at all. {0:N0} people would ";                report += "dearly like to see you assassinated, but we all have our ";                report += "trivial problems.";                double detractors = People * _rnd.NextDouble();                report = String.Format(report, detractors);            }            else            {                report += "A fantastic performance!!!  Charlemagne, Disraeli, and ";                report += "Jefferson combined could not have done better!";            }            report += " So long for now!";            return report;        }        public void BuyLand(int acresToBuy)        {            if (acresToBuy < 0)                throw new NotAValidNumberExeption(NotALegalNumber);            if (acresToBuy * this.LandPrice > Bushels)                throw new NotEnoughBushelsException(String.Format(NotEnoughBushels, Bushels));            this.Acres += acresToBuy;            this.Bushels -= acresToBuy * LandPrice;        }        public void SellLand(int acresToSell)        {            if (acresToSell < 0)                throw new NotAValidNumberExeption(NotALegalNumber);            if (acresToSell > Acres)                throw new NotEnoughAcresException(String.Format(NotEnoughAcres, Acres));            this.Acres -= acresToSell;            this.Bushels += acresToSell * LandPrice;        }        public void FeedPeople(int bushelsForFood)        {            if (bushelsForFood < 0)                throw new NotAValidNumberExeption(NotALegalNumber);            if (bushelsForFood > Bushels)                throw new NotEnoughBushelsException(String.Format(NotEnoughBushels, Bushels));            this.Bushels -= bushelsForFood;            this.BushelsToFeed = bushelsForFood;        }        public void PlantAcres(int acresToPlant)        {            if (acresToPlant < 0)                throw new NotAValidNumberExeption(NotALegalNumber);            if (acresToPlant > Acres)                throw new NotEnoughAcresException(String.Format(NotEnoughAcres, Acres));            if (acresToPlant / 2 > Bushels)                throw new NotEnoughBushelsException(String.Format(NotEnoughBushels, Bushels));            if (People * 10 < acresToPlant)                throw new NotEnoughPeopleException(String.Format(NotEnoughPeople, People));            this.Bushels -= acresToPlant / 2;            this.AcresPlantedLastYear = acresToPlant;        }        public void Run()        {            Year++;            this.PlagueLastYear = Plague();            if (this.PlagueLastYear)                People = People / 2;            LandPrice = GetNewLandPrice();            ImmigrantsLastYear = GetImmigrants();            DeathsLastYear = HowManyPeopleStarved();            PODAK = PODAK + ((double)DeathsLastYear / People) * 100;            TotalStarvations += DeathsLastYear;            People -= DeathsLastYear;            People += ImmigrantsLastYear;            YeildLastYear = GetNewYield();            RatLossLastYear = GetRatFood();            Bushels += (YeildLastYear * AcresPlantedLastYear) - RatLossLastYear;        }        private int HowManyPeopleStarved()        {            if (People * 20 < BushelsToFeed)            {                return 0;            }            int peopleFed = BushelsToFeed / 20;            return People - peopleFed;        }        private int GetNewLandPrice()        {            return _rnd.Next(0, 10) + 17;        }        private int GetNewYield()        {            return _rnd.Next(1, 6);        }        private int GetImmigrants()        {            return _rnd.Next(1, 6) * (20 * Acres + Bushels) / People / 100 + 1;        }        private int GetRatFood()        {            int perc = _rnd.Next(0, 99);            if (perc > 60)                return Bushels / perc;            return 0;        }        private bool Plague()        {            bool perc = _rnd.Next(0, 99) < 15;            return perc;        }        public bool Impeachable()        {            var deathPerc = ((decimal)DeathsLastYear / (DeathsLastYear + People));            return deathPerc > (decimal)0.45;        }    }}namespace Hammurabi{    public class NotAValidNumberExeption : Exception    {        public NotAValidNumberExeption(string message)            : base(message)        {        }    }}namespace Hammurabi{    public class NotEnoughAcresException : Exception    {        public NotEnoughAcresException(string message)            : base(message)        {        }    }}namespace Hammurabi{    public class NotEnoughBushelsException : Exception    {        public NotEnoughBushelsException(string message)            : base(message)        {        }    }}namespace Hammurabi{    public class NotEnoughPeopleException : Exception    {        public NotEnoughPeopleException(string message)            : base(message)        {        }    }}namespace Hammurabi{    class Program    {        static void Main(string args)        {            var k = new Kingdom();            Console.WriteLine(Tab(32) + “Hammurabi”);                        Console.WriteLine(“Try your hand at running ancient Sumeria
for a {0} year term of office.
“, Kingdom.YearsOfRule);            while (k.Year < Kingdom.YearsOfRule)            {                Console.WriteLine(k.GetReport());                if (GetInput(k.BuyLand, string.Format("Land is trading at {0} bushels per acre. How many acres do you wish to buy?", k.LandPrice)) == 0)                    GetInput(k.SellLand, "How many acres do you wish to sell?");                GetInput(k.FeedPeople, "How many bushels do you wish to feed your people?");                GetInput(k.PlantAcres, "How many acres do you wish to plant with seed? ");                k.Run();                if (k.Impeachable())                    break;            }            Console.WriteLine(k.GetReport());            Console.WriteLine(k.EndOfReignReport());            Console.Write(Bell() + Bell() + Bell());            Console.ReadLine();        }        private static int GetInput(Action action, string prompt)        {            int input = 0;            bool success = false;            while (!success)            {                try                {                    Console.WriteLine(prompt);                    if (!Int32.TryParse(Console.ReadLine(), out input))                    {                        throw new ArgumentOutOfRangeException(Kingdom.NotALegalNumber);                    }                    action(input);                    success = true;                }                catch (Exception ex)                {                    Console.WriteLine(ex.Message);                }            }            return input;        }        private static string Tab(int spaces)        {            var tabs = string.Empty;            for (var i = 0; i < spaces; i++)            {                tabs += " ";            }            return tabs;        }        private static string Bell()        {            string bellString = ASCIIEncoding.ASCII.GetString(new byte { 7 });            return bellString;        }    }}