-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicketMachine.cs
More file actions
44 lines (38 loc) · 971 Bytes
/
Copy pathTicketMachine.cs
File metadata and controls
44 lines (38 loc) · 971 Bytes
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
using System;
using System.Collections.Generic;
namespace TicketMachine1_0
{
class TicketMachine
{
static List<Ticket> legalTickets = new List<Ticket>();
public Ticket BuyTicket(string movieName)
{
Ticket t = new Ticket(movieName);
legalTickets.Add(t);
return t;
}
public bool IsValid(Ticket t)
{
foreach (Ticket temp in legalTickets)
{
if (t.Equals(temp))
{
return true;
}
}
return false;
}
public void UseTicket(Ticket t)
{
if (!IsValid(t))
{
Console.WriteLine("ALARM! {0} ticket is not valid!", t);
}
else
{
Console.WriteLine("Have a nice day!");
legalTickets.Remove(t);
}
}
}
}