Site Loader

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Hammurabi{    public class Kingdom    {        public const string NotALegalNumber =            “Hamurabi:  Try to think of whole numbers here.”;        private const string NotEnoughBushels =            “Hamurabi:  Try again.  You have only
{0} bushels of grain. Now then,
“;        private const string NotEnoughAcres =            “Hamurabi:  Try again.  You have only
{0} acres. Now then,
“;        private const string NotEnoughPeople =            “But you have only {0} people to tend to 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 YieldLastYear { get; set; }        public bool PlagueLastYear { get; set; }        public int AcresPlantedLastYear { get; set; }        public double Deaths { get; set; } // Number of deaths that were the kings fault         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; }                public Kingdom()        {            LandPrice = GetNewLandPrice();            DeathsLastYear = 0;            Deaths = 0;            ImmigrantsLastYear = 5;            People = 100;            Acres = 1000;            Year = 1;            RatLossLastYear = 200;            Bushels = 2800;            YieldLastYear = 3;        }        public string GetReport()        {            string report = string.Empty;            if (PlagueLastYear)            {                report += ”
A horrible plage struck! Half the people died.
“;            }            else            {                report += ”
Hammurabi: I report to you that,
“;                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,                YieldLastYear,                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
“;                report += “been impeached and thrown out of office 
“;                                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.

“;            var p1 = Deaths / YearsOfRule;            var l = (double)Acres / People;            report = String.Format(report, p1, TotalStarvations, l, YearsOfRule);            if (p1 > 33 || l 10 || l 3 || l Bushels)                throw new NotEnoughBushelsException(String.Format(NotEnoughBushels, Bushels));            this.Acres += acresToBuy;            this.Bushels -= acresToBuy * LandPrice;        }        public void SellLand(int acresToSell)        {            if (acresToSell Acres)                throw new NotEnoughAcresException(String.Format(NotEnoughAcres, Acres));            this.Acres -= acresToSell;            this.Bushels += acresToSell * LandPrice;        }        public void FeedPeople(int bushelsForFood)        {            if (bushelsForFood Bushels)                throw new NotEnoughBushelsException(String.Format(NotEnoughBushels, Bushels));            this.Bushels -= bushelsForFood;            this.BushelsToFeed = bushelsForFood;        }        public void PlantAcres(int acresToPlant)        {            if (acresToPlant Acres)                throw new NotEnoughAcresException(String.Format(NotEnoughAcres, Acres));            if (acresToPlant / 2 > Bushels)                throw new NotEnoughBushelsException(String.Format(NotEnoughBushels, Bushels));            if (People * 10 60)                return Bushels / perc;            return 0;        }        private bool Plague()        {            bool perc = _rnd.Next(0, 99) (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 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

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


order now

Post Author: admin

x

Hi!
I'm Erica!

Would you like to get a custom essay? How about receiving a customized one?

Check it out