-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeliveryDriver.java
46 lines (40 loc) · 1.5 KB
/
DeliveryDriver.java
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
public class DeliveryDriver {
private final String driverName;
private final String driverLocation;
private int driverLoad;
// Constructor used to create driver from string in the format("%s, %s, %d", driverName, driverLocation, driverLoad)
DeliveryDriver(String commaSeparatedNameLocationLoadString) {
String[] nameLocationLoadArray = commaSeparatedNameLocationLoadString.split(", ");
this.driverName = nameLocationLoadArray[0];
this.driverLocation = nameLocationLoadArray[1];
try {
this.driverLoad = Integer.parseInt(nameLocationLoadArray[2]);}
catch (NumberFormatException e) {
System.out.println("Error: " + e.getMessage());
this.driverLoad = 0;
System.out.println("Driver load has been set to 0 for " + this.driverName + " in " + this.driverLocation);
}
}
// Default values for driver. Used in empty Invoice() constructor.
DeliveryDriver() {
this.driverName = "Generic Driver";
this.driverLocation = "Unknown";
this.driverLoad = 0;
}
// Getters used in Invoice class toString() overridden method.
public String getDriverName() {
return driverName;
}
public String getDriverLocation() {
return driverLocation;
}
public int getDriverLoad() {
return driverLoad;
}
@Override
public String toString() {
return " " + driverName + ", " +
driverLocation + ", " +
driverLoad ;
}
}