Compare commits

...

1 Commits

Author SHA1 Message Date
85acd235f3 clearing code 2023-07-01 16:59:32 +02:00
5 changed files with 21 additions and 68 deletions

View File

@ -6,52 +6,26 @@ 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 Adult();
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

@ -1,17 +1,7 @@
namespace TicketSystem.Tickets
{
public class Adult: Ticket
public class Adult
{
public int price { get; }
public Adult()
{
price = 20;
}
public int PriceWithReduction()
{
return price - price/100*20;
}
}
}

View File

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

View File

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

View File

@ -7,9 +7,13 @@
Adult
}
public interface Ticket
public class Ticket
{
int price { get; }
int PriceWithReduction();
private int price { get; }
public Ticket()
{
price = 20;
}
}
}