Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication6
- {
- abstract class Equipment
- {
- public string Name { get; set; }
- public string ID { get; set; }
- public int CommissioningYear { get; set; }
- public int LifeTime { get; set; } // в годах
- public Equipment(string Name, string ID, int CommissioningYear, int LifeTime)
- {
- this.Name = Name;
- this.ID = ID;
- this.CommissioningYear = CommissioningYear;
- this.LifeTime = LifeTime;
- }
- public abstract bool IsOutdated();
- }
- class Furniture : Equipment
- {
- public string Material { get; set; }
- public double Price;
- public Furniture(string Name, string ID, int CommissioningYear, int LifeTime, string Material, double Price) : base(Name, ID, CommissioningYear, LifeTime)
- {
- this.Material = Material;
- this.Price = Price;
- }
- public override bool IsOutdated()
- {
- if (CommissioningYear + LifeTime < DateTime.Today.Year)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public double GetPrice()
- {
- if(IsOutdated())return Price / 2;
- else return Price;
- }
- }
- class OfficeEquipment : Equipment
- {
- public string Specifications { get; set; }
- public string Type { get; set; }
- public OfficeEquipment(string Name, string ID, int CommissioningYear, int LifeTime, string Specifications, string Type)
- : base(Name, ID, CommissioningYear, LifeTime)
- {
- this.Specifications = Specifications;
- this.Type = Type;
- }
- public override bool IsOutdated()
- {
- int temp = 0;
- for (int i = CommissioningYear + 1; i < DateTime.Today.Year; i++)
- {
- if (i - CommissioningYear <= 3)
- {
- temp++;
- }
- else
- {
- temp += 2;
- }
- }
- if (temp > LifeTime)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- class SportEquipment : Equipment
- {
- public string KindOfSport { get; set; }
- private bool isValid = true;
- public SportEquipment(string Name, string ID, int CommissioningYear, int LifeTime, string KindOfSport)
- : base(Name, ID, CommissioningYear, LifeTime)
- {
- this.KindOfSport = KindOfSport;
- }
- public override bool IsOutdated()
- {
- if (isValid == false)
- {
- return false;
- }
- if (CommissioningYear + LifeTime < DateTime.Today.Year)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public void ToDead()
- {
- isValid = false;
- }
- }
- class Tabel
- {
- ArrayList list = new ArrayList();
- public void AddRecord(Equipment eq)
- {
- list.Add(eq);
- }
- public void PrintAllRecords()
- {
- Console.WriteLine("{0, -15}{1, -40}{2, -15}", "ID", "Имя", "Статус");
- foreach (Equipment eq in list)
- {
- if (eq.IsOutdated() == true)
- {
- Console.WriteLine("{0, -15}{1, -40}{2, -15}", eq.ID, eq.Name, "Устарел");
- }
- else
- {
- Console.WriteLine("{0, -15}{1, -40}{2, -15}", eq.ID, eq.Name, "Годен");
- }
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Tabel tabel = new Tabel();
- tabel.AddRecord(new OfficeEquipment("Стол", "ASD3154AF", 2010, 8, "Столик", "Это стол"));
- tabel.AddRecord(new OfficeEquipment("Стул", "ASD31523F", 2014, 8, "Стулик", "Это стул"));
- tabel.AddRecord(new OfficeEquipment("Кулер", "ASNS154AF", 2015, 6, "Кулик", "Это кулер"));
- tabel.AddRecord(new OfficeEquipment("Стол", "AS63554AF", 2017, 3, "Столик", "Это стол"));
- tabel.AddRecord(new SportEquipment("Бита", "BASF2YGBH", 2010, 9, "Бейсбол"));
- tabel.AddRecord(new SportEquipment("Мяч", "435765235", 2018, 2, "Футбол"));
- tabel.AddRecord(new Furniture("Диван", "158263529", 2013, 8, "Кожа"));
- tabel.AddRecord(new Furniture("Диван 2", "182536529", 2013, 3, "неКожа"));
- tabel.PrintAllRecords();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment