Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
85acd235f3 |
@ -6,52 +6,26 @@ namespace TicketSystem
|
|||||||
{
|
{
|
||||||
public class Order
|
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)
|
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)
|
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()
|
public void ApplyReduction()
|
||||||
{
|
{
|
||||||
price = 0;
|
|
||||||
foreach (var ticket in tickets)
|
|
||||||
{
|
|
||||||
price += ticket.PriceWithReduction();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,7 @@
|
|||||||
namespace TicketSystem.Tickets
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
namespace TicketSystem.Tickets
|
namespace TicketSystem.Tickets
|
||||||
{
|
{
|
||||||
public class Child: Ticket
|
public class Child
|
||||||
{
|
{
|
||||||
public int price { get; }
|
public int price { get; }
|
||||||
|
|
||||||
@ -8,10 +8,5 @@
|
|||||||
{
|
{
|
||||||
price = 5;
|
price = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int PriceWithReduction()
|
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,7 @@
|
|||||||
namespace TicketSystem.Tickets
|
namespace TicketSystem.Tickets
|
||||||
{
|
{
|
||||||
public class Student: Ticket
|
public class Student
|
||||||
{
|
{
|
||||||
public int price { get; }
|
|
||||||
|
|
||||||
public Student()
|
|
||||||
{
|
|
||||||
price = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int PriceWithReduction()
|
|
||||||
{
|
|
||||||
return 10-3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,9 +7,13 @@
|
|||||||
Adult
|
Adult
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Ticket
|
public class Ticket
|
||||||
{
|
{
|
||||||
int price { get; }
|
private int price { get; }
|
||||||
int PriceWithReduction();
|
|
||||||
|
public Ticket()
|
||||||
|
{
|
||||||
|
price = 20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user