-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
174 lines (152 loc) · 7.25 KB
/
Copy pathMain.java
File metadata and controls
174 lines (152 loc) · 7.25 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
Your Name: Jaiden Roman
Pace Email: JR79854N@pace.edu
*/
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
VideoList inventory = new VideoList();
RentList rented = new RentList();
CustomerList customers = new CustomerList();
inventory.insert("The Okay Movie", "675937584637");
inventory.insert("The Amazing Movie", "123456789012");
inventory.insert("The Worst Movie in Existence", "210987654321");
inventory.insert("A Movie", "268467895371");
customers.insert("Bob", "Whilikers", "109209309");
customers.insert("Phil", "Bill", "205205205");
customers.insert("Alexa", "AI", "923456789");
customers.insert("Luigi", "Mario", "92955MARIO");
System.out.println("Welcome! What do you wish to do? Enter q to quit. Enter c for commands: ");
String input = scan.nextLine();
while(!input.equalsIgnoreCase("q"))
{
if(input.equalsIgnoreCase("displayrented"))
{
rented.printInOrder();
}
if(input.equalsIgnoreCase("displayinventory"))
{
inventory.printInOrder();
}
if(input.equalsIgnoreCase("displaycustomers"))
{
customers.printInOrder();
}
if(input.equalsIgnoreCase("c"))
{
System.out.println("To add a customer, type newcustomer. To add a video, type newvideo. To check the status of a rented video. type rentstatus. To make a rent, type rent. To make a return, type return. To display: displayrented, displayinventory, displaycustomers");
}
//O(n)
if(input.equalsIgnoreCase("rentstatus"))
{
System.out.println("Enter the name of the video you would like to check the status of: ");
String name = scan.nextLine();
Video m = rented.findByName(name);
if(m == null) System.out.println("This video is not currently rented");
else
{
System.out.println(m.renter.firstName + " " +m.renter.lastName+" has " + m.name + " rented. Their phone number is: " + m.renter.phoneNumber);
}
}
//O(log(n))
if(input.equalsIgnoreCase("return"))
{
System.out.println("Please enter the phone number of the customer: ");
String phoneNumber = scan.nextLine();
Customer c = customers.find(phoneNumber);
if(c == null) System.out.println("The customer cannot be found.");
else
{
System.out.println("Please enter the barcode of the movie to be returned: ");
String barcode = scan.nextLine();
Video m = rented.find(barcode);
if(m == null) System.out.println("The video cannot be found.");
else
{
boolean there = false;
for (int i = 0; i <3; i++)
{
if(c.videoList[i] == null);
else if(c.videoList[i].equals(m))
{
c.videoList[i] = null;
there = true;
}
}
if(there == true)
{
inventory.insert(m.name, m.barcode);
rented.remove(m.name, m.barcode);
System.out.println(m.name + " successfully returned.");
}
else
{
System.out.println("The customer does not have this movie rented");
}
}
}
}
//O(log(n))
if(input.equalsIgnoreCase("newvideo"))
{
System.out.println("Please enter the video's name: ");
String name = scan.nextLine();
String barcode = "placeholder";
System.out.println("Please enter the video's barcode");
barcode = scan.nextLine();
while(barcode.length() != 12)
{
System.out.println("Invalid barcode (must be 12 characters long)");
barcode = scan.nextLine();
}
inventory.insert(name, barcode);
System.out.println(name + " successfully added.");
}
//O(log(n))
if(input.equalsIgnoreCase("newcustomer"))
{
System.out.println("Please enter the customer's first name: ");
String firstName = scan.nextLine();
System.out.println("Please enter the customer's last name: ");
String lastName = scan.nextLine();
System.out.println("Please enter the customer's phone number: ");
String phoneNumber = scan.nextLine();
customers.insert(firstName, lastName, phoneNumber);
System.out.println(firstName + " successfully added.");
}
//O(log(n))
if(input.equalsIgnoreCase("rent"))
{
System.out.println("Please enter the barcode of the movie you wish to rent: ");
input = scan.nextLine();
Video m = inventory.find(input);
if(m == null) System.out.println("This barcode cannot be found");
else
{
System.out.println("Which customer wishes to rent " + m.name + "? Please enter their phone number.");
input = scan.nextLine();
Customer c = customers.find(input);
if(c==null) System.out.println("This customer cannot be found");
else
{
if(c.videoList[2] != null && c.videoList[1] != null && c.videoList[0] !=null) System.out.println(c.firstName + " has too many videos rented");
else
{
rented.insert(m.name, m.barcode, c);
if(c.videoList[0] == null) c.videoList[0] = m;
else if(c.videoList[1] == null) c.videoList[1] = m;
else if(c.videoList[2] == null) c.videoList[2] = m;
inventory.remove(m.name, m.barcode);
System.out.println(m.name + " successfully rented.");
}
}
}
}
System.out.println("Is there anything else you would like to do? Enter q to quit. Enter c for commands: ");
input = scan.nextLine();
}
}
}