Skip to content

Commit 0d685c5

Browse files
committed
Adding files
1 parent 0c50f53 commit 0d685c5

File tree

3 files changed

+446
-0
lines changed

3 files changed

+446
-0
lines changed

autosDB.sqlite

212 KB
Binary file not shown.

src/Menu.java

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
import java.sql.*;
2+
import java.util.*;
3+
4+
public class Menu {
5+
6+
public static void main(String[] args) {
7+
//Main.query();
8+
// Build menu
9+
boolean menu = true;
10+
Scanner input = new Scanner(System.in);
11+
12+
System.out.println("");
13+
System.out.println("");
14+
15+
System.out.println("############################");
16+
System.out.println("############################");
17+
System.out.println("######### WELCOME ##########");
18+
System.out.println("############################");
19+
System.out.println("############################");
20+
21+
// Enter primary menu
22+
while(menu){
23+
24+
25+
// Primary menu options
26+
System.out.println("");
27+
System.out.println("What would you like to do?");
28+
System.out.println("");
29+
30+
System.out.println("1.) Add new accident");
31+
System.out.println("2.) Accident lookup");
32+
System.out.println("3.) Check connection");
33+
System.out.println("4.) Test");
34+
System.out.println("");
35+
36+
37+
int reply = input.nextInt(); // User menu selection
38+
39+
// Menu button functions
40+
switch (reply) {
41+
case 1:
42+
boolean adding = true;
43+
44+
// Enter record adding menu
45+
accidents: while(adding) {
46+
47+
48+
// Enter date
49+
input.nextLine();
50+
System.out.println("Enter date:");
51+
String date = input.nextLine();
52+
System.out.println(date + " was read");
53+
System.out.println("");
54+
55+
// Enter city
56+
System.out.println("Enter city:");
57+
String city = input.nextLine();
58+
System.out.println(city + " was read");
59+
System.out.println("");
60+
61+
// Enter state
62+
System.out.println("Enter state:");
63+
String state = input.nextLine();
64+
System.out.println(state + " was read");
65+
System.out.println("");
66+
67+
// Allow user to validate input or exit
68+
System.out.println("Look correct? [y/n], 'q' to exit");
69+
String choice = input.next();
70+
System.out.println("");
71+
72+
// Case if information incorrect, reset entry
73+
if (choice.equals("n")) {
74+
System.out.println("Information not added. Try again.");
75+
76+
// Case if user wants to exit application
77+
} else if (choice.equals("q")){
78+
System.out.println("Are you sure? Current accident information will be lost! [y/n]");
79+
String sure1 = input.next();
80+
81+
// Make sure user wants to exit
82+
if (sure1.equals("y")){
83+
System.out.println("Exiting...");
84+
System.out.println("");
85+
break;
86+
} else {
87+
choice = "n";
88+
}
89+
}
90+
else if (choice.equals("y")){
91+
92+
boolean addingVehicle = true;
93+
while(addingVehicle){
94+
95+
// Enter
96+
input.nextLine();
97+
System.out.println("Enter VIN:");
98+
String vin = input.nextLine();
99+
System.out.println(vin + " was read");
100+
System.out.println("");
101+
102+
System.out.println("Enter damages:");
103+
float damages = input.nextFloat();
104+
input.nextLine();
105+
System.out.println(damages + " was read");
106+
System.out.println("");
107+
108+
System.out.println("Enter driver ssn:");
109+
String driver_ssn= input.nextLine();
110+
System.out.println(driver_ssn + " was read");
111+
System.out.println("");
112+
113+
System.out.println("Look correct? [y/n], 'q' to return to main menu.");
114+
String choice2 = input.next();
115+
System.out.println("");
116+
117+
if (choice2.equals("n")) {
118+
System.out.println("Vehicle not added. Try again.");
119+
120+
} else if (choice2.equals("q")){
121+
System.out.println("Are you sure? Record information will be lost! [y/n]");
122+
String sure = input.next();
123+
if (sure.equals("y")){
124+
System.out.println("Exiting...");
125+
System.out.println("");
126+
break accidents;
127+
} else {
128+
choice2 = "n";
129+
}
130+
}
131+
else if (choice2.equals("y")){
132+
133+
queries.addVehicle(vin, damages, driver_ssn);
134+
System.out.println("Vehicle added!");
135+
System.out.println("Add another vehicle? [y/n]");
136+
String cont2 = input.next();
137+
138+
// Check user input
139+
if (cont2.equals("n")){
140+
queries.addAccident(date, city, state);
141+
System.out.println("Record added!");
142+
143+
break;
144+
} else if (!cont2.equals("y")){
145+
146+
// Prompt user again for correct input
147+
System.out.println("Invalid option enter 'n' to exit or 'y' to continue.");
148+
choice2 = input.nextLine();
149+
}
150+
151+
}}
152+
153+
154+
System.out.println("Add another accident? [y/n]");
155+
String cont = input.next();
156+
157+
// Check user input
158+
if (cont.equals("n")){
159+
System.out.println("Update successful!");
160+
break;
161+
} else if (!cont.equals("y")){
162+
163+
// Prompt user again for correct input
164+
System.out.println("Invalid option enter 'n' to exit or 'y' to continue.");
165+
choice = input.nextLine();
166+
}
167+
} else {
168+
System.out.println("Invalid option type 'a' to add record, 'c' to cancel");
169+
choice = input.nextLine();
170+
}
171+
}
172+
break;
173+
case 2:
174+
boolean querying = true;
175+
outer: while (querying){
176+
177+
System.out.println("");
178+
System.out.println("How would you like to search?");
179+
System.out.println("1.) Look up by AID");
180+
System.out.println("2.) Look up by criteria");
181+
System.out.println("Press '0' to exit.");
182+
183+
int reply2 = input.nextInt();
184+
switch (reply2){
185+
case 1:
186+
input.nextLine();
187+
System.out.println("Enter Accident ID:");
188+
int aid = input.nextInt();
189+
queries.findAccidentbyID(aid);
190+
break;
191+
192+
case 2:
193+
194+
// initialize default values
195+
String dateRangeStart = "0000-00-00";
196+
String dateRangeEnd = "9999-99-99";
197+
float avgDamageMin = 0;
198+
float avgDamageMax = 99999999;
199+
float totalDamageMin = 0;
200+
float totalDamageMax = 99999999;
201+
202+
203+
input.nextLine();
204+
System.out.println("Specify date range [Type 'none' to skip]");
205+
System.out.println("Start date:");
206+
207+
dateRangeStart = input.nextLine();
208+
209+
System.out.println("Starting at: " + dateRangeStart);
210+
211+
212+
if (!dateRangeStart.equals("none")){
213+
214+
System.out.println("End date:");
215+
dateRangeEnd = input.nextLine();
216+
System.out.println("Ending at: " + dateRangeEnd);
217+
218+
} else {
219+
dateRangeStart = "0000-00-00";// reset
220+
}
221+
System.out.println("Specify average damage range [Enter -1 to skip]");
222+
223+
System.out.println("Minimum value:");
224+
avgDamageMin = input.nextFloat();
225+
226+
if (!(avgDamageMin == -1)){
227+
System.out.println("Maximum value:");
228+
avgDamageMax = input.nextFloat();
229+
} else {
230+
231+
avgDamageMin = 0; //reset
232+
}
233+
System.out.println("Specify total damage range [Enter -1 to skip]");
234+
235+
236+
System.out.println("Minimum value:");
237+
totalDamageMin = input.nextFloat();
238+
239+
if (!(totalDamageMin ==-1)){
240+
241+
System.out.println("Maximum value:");
242+
totalDamageMax = input.nextFloat();
243+
} else {
244+
totalDamageMin = 0; // reset
245+
}
246+
247+
248+
// call
249+
queries.findAccidentbyCriteria(dateRangeStart, dateRangeEnd, avgDamageMin, avgDamageMax, totalDamageMin, totalDamageMax);
250+
251+
break;
252+
case 0:
253+
break outer;
254+
}
255+
256+
}
257+
break;
258+
259+
case 3:
260+
queries.checkConnection();
261+
break;
262+
263+
case 4:
264+
break;
265+
}
266+
}
267+
268+
269+
}
270+
}

0 commit comments

Comments
 (0)