Compare commits

..

1 Commits

Author SHA1 Message Date
0c80706a4b add overriding 2023-07-01 17:01:12 +02:00
6 changed files with 59 additions and 22 deletions

View File

@ -6,26 +6,52 @@ namespace TicketSystem
{
public class Order
{
private List<Ticket> tickets;
private int price;
public int Price => price;
public Order()
{
tickets = new List<Ticket>();
price = 0;
}
/// <summary>
/// Add the given ticket to the order
/// </summary>
public void AddTicket(Ticket ticket)
{
tickets.Add(ticket);
price += ticket.price;
}
/// <summary>
/// Add the correct ticket based on its type to the order
/// </summary>
public void AddTicket(TicketType type)
{
Ticket t;
switch (type)
{
case TicketType.Child:
t = new Child();
tickets.Add(t);
price += t.price;
break;
case TicketType.Student:
t = new Student();
tickets.Add(t);
price += t.price;
break;
case TicketType.Adult:
t = new Ticket();
tickets.Add(t);
price += t.price;
break;
}
}
/// <summary>
/// Change the price to have the reduction on it
/// </summary>
public void ApplyReduction()
{
price = 0;
foreach (var ticket in tickets)
{
price += ticket.PriceWithReduction();
}
}
}
}

View File

@ -42,7 +42,6 @@
<Compile Include="Order.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tickets\Adult.cs" />
<Compile Include="Tickets\Child.cs" />
<Compile Include="Tickets\Student.cs" />
<Compile Include="Tickets\Ticket.cs" />

View File

@ -1,7 +0,0 @@
namespace TicketSystem.Tickets
{
public class Adult
{
}
}

View File

@ -1,6 +1,6 @@
namespace TicketSystem.Tickets
{
public class Child
public class Child: Ticket
{
public int price { get; }
@ -8,5 +8,10 @@
{
price = 5;
}
public int PriceWithReduction()
{
return 2;
}
}
}

View File

@ -1,7 +1,17 @@
namespace TicketSystem.Tickets
{
public class Student
public class Student: Ticket
{
public int price { get; }
public Student()
{
price = 10;
}
public int PriceWithReduction()
{
return 10-3;
}
}
}

View File

@ -9,11 +9,15 @@
public class Ticket
{
private int price { get; }
public int price { get; }
public Ticket()
{
price = 20;
}
public int PriceWithReduction()
{
return price - price/100*20;
}
}
}