Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace WeaponsReport
- {
- internal class Program
- {
- static void Main()
- {
- SoldierBase soldierBase = new SoldierBase();
- List<Soldier> soldiers = soldierBase.Fill();
- soldierBase.Show(soldiers);
- Console.WriteLine("\n Received data");
- List<Soldier> selectedSoldiers = soldierBase.GetDataset(soldiers);
- soldierBase.Show(selectedSoldiers);
- Console.ReadKey();
- }
- }
- public class SoldierBase
- {
- public List<Soldier> Fill()
- {
- SoldierProvider soldierProvider = new SoldierProvider();
- return soldierProvider.GetSoldiers();
- }
- public void Show(List<Soldier> soldiers)
- {
- foreach (Soldier soldier in soldiers)
- {
- string serviceTime = soldier.ServiceTime != 0 ? soldier.ServiceTime.ToString() : null;
- Console.WriteLine($"{soldier.Rank} {soldier.Name}\t{soldier.Weapon} {serviceTime}");
- }
- }
- public List<Soldier> GetDataset(List<Soldier> soldiers)
- {
- List<Soldier> selectedSoldiers = new List<Soldier>();
- var dataset = soldiers.Select(soldier => (soldier.Name, soldier.Rank));
- foreach (var record in dataset)
- {
- selectedSoldiers.Add(new Soldier(record.Name, record.Rank));
- }
- return selectedSoldiers.ToList();
- }
- }
- public class SoldierProvider
- {
- private readonly List<Soldier> _soldiers;
- public SoldierProvider()
- {
- _soldiers = new List<Soldier>() {
- new Soldier( "Ivanov","private","assault rifle",1),
- new Soldier( "Kuznetsov","private","assault rifle",2),
- new Soldier( "Smirnov","private","assault rifle",1),
- new Soldier( "Popov","private","machine gun",2),
- new Soldier( "Petrov","sergeant","assault rifle",5),
- };
- }
- public List<Soldier> GetSoldiers()
- {
- return _soldiers;
- }
- }
- public class Soldier
- {
- public Soldier(string name, string rank)
- {
- Name = name;
- Rank = rank;
- }
- public Soldier(string name, string rank, string weapon, int serviceTime)
- {
- Name = name;
- Rank = rank;
- Weapon = weapon;
- ServiceTime = serviceTime;
- }
- public string Name { get; private set; }
- public string Rank { get; private set; }
- public string Weapon { get; private set; }
- public int ServiceTime { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement