-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicketMaster.java
More file actions
137 lines (103 loc) · 4.1 KB
/
TicketMaster.java
File metadata and controls
137 lines (103 loc) · 4.1 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import java.util.ArrayList;
import java.io.*;
public class TicketMaster
{
public static void main (String[] args) throws IOException
{
// Logging that program has been launched
Utils.LogIncrease();
System.out.println ("Welcome to the online TicketMaster");
System.out.println ("A default event has been created for you, to customize or add new events, enter the operator menu.");
// Generating default event
NewStadium a = new NewStadium ("Concert", "01/01/2000");
// list of NewStadiums, contains all the events created
ArrayList<NewStadium> events = new ArrayList<> ();
// Adding default event to the list of events
events.add (a);
// List of strings containing info on tickets, according to their confirmation number
// example, index 0 is for confirmation number 1001
ArrayList confirmation = new ArrayList ();
// this field is used in the numbering of confirmation numbers and is incremented as tickets are purchased
int codeNumber = 1000;
int userchoice;
do
{
System.out.println ("\nPlease enter which option you wish to use\n");
System.out.println ("1) Purchase Ticket");
System.out.println ("2) Check Ticket Status");
System.out.println ("3) Check Availability");
System.out.println ("4) Operator Menu");
System.out.println ("Enter 0 to exit TicketMaster");
userchoice = TextIO.getlnInt ();
if (userchoice == 1)
{
System.out.println ("Purchasing Ticket\n");
// Selecting an event
NewStadium temp = Utils.SelectEvent(events);
// Replace temp with a if running on old java
Utils.Purchase (temp, confirmation);
System.out.println ("Forwarding to process your payment");
System.out.println ("...");
try // Simulating payment processing
{
Thread.sleep (1000);
System.out.println ("...");
Thread.sleep (1000);
System.out.println ("...");
Thread.sleep (1000);
}
catch (InterruptedException ex)
{
Thread.currentThread ().interrupt ();
}
codeNumber++; // Incrementing the confirmation code and giving it to the user
System.out.println ("Transaction Complete. Your confirmation code is " + codeNumber + ". Returning to main menu.");
try // Simple timer to allow reading
{
Thread.sleep (2000);
}
catch (InterruptedException ex)
{
Thread.currentThread ().interrupt ();
}
}
else if (userchoice == 2)
{
System.out.println ("Check Ticket Status");
System.out.print ("\nPlease enter your confirmation code: ");
int codeInput = TextIO.getlnInt ();
// Checking if input is valid, if number does not exist then asks again
while (codeInput <= 1000 || codeInput - 1001 >= confirmation.size() || codeInput < 0)
{
if (codeInput < 1000 || codeInput - 1001 >= confirmation.size () || codeInput - 1001 < 0)
System.out.println ("That confirmation code does not exist. Please try again or enter 0 to exit.");
codeInput = TextIO.getlnInt ();
if(codeInput == 0)
break;
}
if(codeInput == 0)
System.out.println("Returning to main menu.");
else // Prints the info of that ticket, calculates index by reducing the confirmation code by 1001
System.out.println ("Your ticket is for: " + confirmation.get (codeNumber - 1001));
}
else if (userchoice == 3)
{
System.out.println ("Check Availability\n");
// Selecting an event and printing the stadium and number of seats taken
NewStadium temp = Utils.SelectEvent(events);
temp.print(temp);
System.out.println("There are " + temp.sumReserved(temp) + " seats taken out of 32");
}
else if (userchoice == 4)
{
System.out.println ("Operator Menu");
OperatorMenu.OperatorMenuOption(events);
}
else if (userchoice == 0)
System.out.println ("Exiting TicketMaster");
else
System.out.println ("Invalid option. Please enter again");
}
while (userchoice != 0);
}
}