public static void Main(string[] args) { Console.WriteLine("Start of program. Press any key...."); Console.ReadKey(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { ToyOrderBook.SetupOrderLists(); DataReader.OpenReadStream(DataReader.filePath); Console.WriteLine(DataReader.ReadHeaderLine()); ToyOrderBook.AddNewOrdersToOrderBook(DataReader.ReadLinesFromStream(N_TOYS)); DataReader.CloseReadStream(); ElfCoordinator.HireElves(N_ELVES); int remainingOrders = ToyOrderBook.CountAllOrdersInBook(); int processedOrders = 0; while (remainingOrders > 0) { processedOrders++; bool shouldPrint = processedOrders % 1000 == 0; if (shouldPrint) { PrintProgress(processedOrders); } Elf elf = ElfCoordinator.PickNextElf(); ToyOrder toy = elf.ChooseToy(); elf.BuildToy(toy); remainingOrders = ToyOrderBook.CountAllOrdersInBook(); } ToyOrderBook.PrintCompletedOrdersToConsole(); Console.WriteLine(String.Format("Completed Toys: {0}", ToyOrderBook.completedOrders.Count)); ToyOrder lastToy = ToyOrderBook.lastOrderCompleted; Console.WriteLine(String.Format("Last Toy Completed: Toy {0} completed at {1} {2}", lastToy.iD, lastToy.finishTime.ToShortDateString(), lastToy.finishTime.ToShortTimeString())); Console.WriteLine(String.Format("Total Minutes: {0}", CalculateTotalMinutes())); Console.WriteLine(String.Format("Score: {0}", CalculateScore())); WriteResultsFile(); } catch (Exception ex) { Console.WriteLine("In 'Main()'"); Console.WriteLine(ex.Message); Console.WriteLine(ex.ToString()); } stopwatch.Stop(); Console.WriteLine(String.Format("Elapsed Time: {0}", stopwatch.Elapsed.ToString())); Console.WriteLine("End of program."); }
public void BuildToy(ToyOrder toy) { int minutesTillFinished = (int)Math.Ceiling((double)toy.durationMinutes / this.productivity); DateTime startTime = CalculateStartTime(toy, minutesTillFinished); this.workingTill = startTime.AddMinutes(minutesTillFinished); int sanctionedMinutes = Hours.CalculateSanctionedMinutes(startTime, minutesTillFinished); int unsanctionedMinutes = minutesTillFinished - sanctionedMinutes; this.neededRest = unsanctionedMinutes; toy.elfId = this.id; toy.startTime = startTime; toy.finalDuration = minutesTillFinished; UpdateProductivity(sanctionedMinutes, unsanctionedMinutes); ToyOrderBook.completedOrders.Add(toy); ToyOrderBook.RemoveOrderFromBooks(toy); }