-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathProduct.cs
More file actions
51 lines (43 loc) · 1.25 KB
/
Product.cs
File metadata and controls
51 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace Accounting
{
public class Product
{
public Product(string name, int price, int units)
{
this.Name = name;
this.Price = price;
this.Units = units;
}
public string Name { get; private set; }
public int Price { get; private set; }
public int Units { get; private set; }
public virtual int TotalCost()
{
return this.Price * this.Units;
}
public virtual void AddUnits(int units)
{
this.Units += units;
}
public override string ToString()
{
return $"{this.Name} - ${this.Price} (x{this.Units}) = ${this.TotalCost()}";
}
}
public class DiscountProduct : Product
{
public double Discount { get; private set; }
public DiscountProduct(string name, int price, int units, double discount) : base(name, price, units)
{
this.Discount = discount;
}
public override int TotalCost()
{
return (int)(base.TotalCost() * (1 - this.Discount));
}
public override string ToString()
{
return base.ToString() + $" [-{this.Discount * 100:0.0}%]";
}
}
}