public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); CitizenFactory factory = new CitizenFactory(); List <Buyer> buyers = new List <Buyer>(); for (int i = 0; i < n; i++) { string[] arr = Console.ReadLine().Split(); factory.GetCitizen(arr, buyers); } string command = Console.ReadLine(); while (command != "End") { foreach (var b in buyers) { b.BuyFood(command); } command = Console.ReadLine(); } Console.WriteLine(buyers.Sum(x => x.Food)); }
public Engine(IReader reader, IWriter writer) { this.reader = reader; this.writer = writer; citizenFactory = new CitizenFactory(); robotFactory = new RobotFactory(); list = new List <string>(); }
public Engine(IReader reader, IWriter writer) { this.reader = reader; this.writer = writer; citizenFactory = new CitizenFactory(); rebelFactory = new RebelFactory(); buyers = new List <IBuyer>(); }
/// <summary> /// Retrieves single citizen by id. /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <Result <CitizenDto> > GetCitizenAsync(int id) { try { var citizen = await this.Db.Citizens.SingleOrDefaultAsync(x => x.Id == id); if (citizen == null) { return(Result <CitizenDto> .Failure("Citizen not found.")); } return(Result <CitizenDto> .Success(CitizenFactory.Create(citizen))); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Get Citizen method."); return(Result <CitizenDto> .Failure("Error in Get Citizen method.")); } }
public void Run() { int numberInputs = int.Parse(Console.ReadLine()); for (int i = 0; i < numberInputs; i++) { string[] commandArgs = Console.ReadLine().Split(); if (commandArgs.Length == 4) { IBuyer citizen = CitizenFactory.CreateCitizen(commandArgs); population.Add(citizen); } else if (commandArgs.Length == 3) { IBuyer rebel = RebelFactory.CreateRebel(commandArgs); population.Add(rebel); } } while (true) { string input = Console.ReadLine(); if (input == "End") { break; } IBuyer buyer = population.FirstOrDefault(b => b.Name == input); if (buyer != null) { buyer.BuyFood(); } } Console.WriteLine(population.Sum(b => b.Food)); }
public void Run() { while (true) { string input = Console.ReadLine(); if (input == "End") { break; } string[] commandArgs = input.Split(); string individ = commandArgs[0]; if (individ == "Citizen") { IBirthable citizen = CitizenFactory.CreateCitizen(commandArgs.Skip(1).ToArray()); population.Add(citizen); } else if (individ == "Pet") { IBirthable pet = PetFactory.CreatePet(commandArgs.Skip(1).ToArray()); population.Add(pet); } } string yearToShow = Console.ReadLine(); foreach (var birthable in population) { if (birthable.Birthdate.EndsWith(yearToShow)) { Console.WriteLine(birthable.Birthdate); } } }
public void Run() { while (true) { string input = Console.ReadLine(); if (input == "End") { break; } string[] commandArgs = input.Split(); if (commandArgs.Length == 3) { IIdentifiable citizen = CitizenFactory.CreateCitizen(commandArgs); population.Add(citizen); } else if (commandArgs.Length == 2) { IIdentifiable robot = RobotFactory.CreateRobot(commandArgs); population.Add(robot); } } string fakeIdEnd = Console.ReadLine(); foreach (var identifiable in population) { if (identifiable.Id.EndsWith(fakeIdEnd)) { Console.WriteLine(identifiable.Id); } } }