Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
85acd235f3 |
@ -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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@
|
||||
<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" />
|
||||
|
7
TicketSystem/Tickets/Adult.cs
Normal file
7
TicketSystem/Tickets/Adult.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace TicketSystem.Tickets
|
||||
{
|
||||
public class Adult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,15 +9,11 @@
|
||||
|
||||
public class Ticket
|
||||
{
|
||||
public int price { get; }
|
||||
private int price { get; }
|
||||
|
||||
public Ticket()
|
||||
{
|
||||
price = 20;
|
||||
}
|
||||
|
||||
public int PriceWithReduction()
|
||||
{
|
||||
return price - price/100*20;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user