public abstract class Product
public DateTime productionDate;
public DateTime expirationDate;
public DateTime ProductionDate
return this.productionDate;
this.productionDate = value;
public abstract DateTime GetExpirationDate();
public class Dairy : Product
public override DateTime GetExpirationDate()
return this.ProductionDate.Date.AddDays(7);
Console.WriteLine("I'm a dairy product. My name is {0} and I weight {1} kg, I was produced by {2} in {3} and I wil expire in {4}.\n", this.name, this.weight, this.producer, this.ProductionDate.ToShortDateString(), this.GetExpirationDate().ToShortDateString());
public class Fruit : Product
public override DateTime GetExpirationDate()
return this.ProductionDate.Date.AddDays(2);
Console.WriteLine("I'm a fruit. My name is {0} and I weight {1} kg, I was produced by {2} in {3} and I wil expire in {4}.\n", this.name, this.weight, this.producer, this.ProductionDate.ToShortDateString(), this.GetExpirationDate().ToShortDateString());
public class Beverage : Product
public override DateTime GetExpirationDate()
return this.ProductionDate.Date.AddYears(3);
Console.WriteLine("I'm a beverage. My name is {0} and I weight {1} kg, I was produced by {2} in {3} and I wil expire in {4}.\n", this.name, this.weight, this.producer, this.ProductionDate.ToShortDateString(), this.GetExpirationDate().ToShortDateString());
public class Bread : Product
public override DateTime GetExpirationDate()
return this.ProductionDate.Date.AddDays(4);
Console.WriteLine("I'm a bread. My name is {0} and I weight {1} kg, I was produced by {2} in {3} and I wil expire in {4}.\n", this.name, this.weight, this.producer, this.ProductionDate.ToShortDateString(), this.GetExpirationDate().ToShortDateString());
public static void Main()
Beverage cola = new Beverage();
cola.producer = "Coca Cola";
cola.ProductionDate = new DateTime(2018,12,03);
Dairy lapte = new Dairy();
lapte.producer = "Albalact";
lapte.ProductionDate = new DateTime(2018,12,03);
Fruit banana = new Fruit();
banana.producer = "banana tree";
banana.ProductionDate = new DateTime(2018,12,03);
Bread panica = new Bread();
panica.producer = "mamica";
panica.ProductionDate = new DateTime(2018,12,03);