-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParkingTicketSimulator.java
More file actions
76 lines (59 loc) · 2.51 KB
/
ParkingTicketSimulator.java
File metadata and controls
76 lines (59 loc) · 2.51 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
import java.util.Scanner;
public class ParkingTicketSimulator {
public static int checkDataType(Scanner keyboard) {
int numberInput = 0;
while (keyboard.hasNext()) {
if (keyboard.hasNextInt()) {
numberInput = keyboard.nextInt();
keyboard.nextLine();
break;
} else {
System.out.println("\tInvalid input. Numbers Only.");
keyboard.nextLine();
System.out.print("\tTry Again: ");
}
}
return numberInput;
}
public static void checkLen(String[] carInfo, Scanner keyboard) {
while (true) {
carInfo[3] = keyboard.nextLine();
if (carInfo[3].length() == 7) {
break;
} else {
System.out.print("\t7 characters only: ");
}
}
}
public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
String[] carInfo = new String[4];
String nameOfOfficer = "";
int parkedMinutes = 0;
int boughtMinutes = 0;
int theBadge = 0;
System.out.print("Enter Make: ");
carInfo[0] = keyboard.nextLine();
System.out.print("Enter Model: ");
carInfo[1] = keyboard.nextLine();
System.out.print("Enter Color: ");
carInfo[2] = keyboard.nextLine();
System.out.print("Enter License Plate(License Plate Must Be 7 Characters Long): ");
checkLen(carInfo, keyboard);
System.out.print("Enter The Minutes Purchased: ");
boughtMinutes = checkDataType(keyboard);
System.out.print("How Long Did The Driver Stay(in minutes): ");
parkedMinutes = checkDataType(keyboard);
System.out.print("Name Of The Deputy On Scene: ");
nameOfOfficer = keyboard.nextLine();
System.out.print("Deputy Badge Number: ");
theBadge = checkDataType(keyboard);
ParkedCar theCar = new ParkedCar(carInfo[0], carInfo[1], carInfo[2], carInfo[3], parkedMinutes);
PoliceOfficer deputyInfo = new PoliceOfficer(theBadge, nameOfOfficer);
ParkingMeter purchasedMin = new ParkingMeter(boughtMinutes);
ParkingTicket civillianVehicle = new ParkingTicket(theCar, deputyInfo, purchasedMin);
String theFinalVerdict = PoliceOfficer.issueTicket(theCar, deputyInfo, civillianVehicle);
System.out.println("\nInfraction Outcome:\n"+theFinalVerdict);
keyboard.close();
}
}