-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrip.java
66 lines (58 loc) · 2.41 KB
/
Trip.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package it.uniud.poo.trasporti_2024;
import lombok.Getter;
import lombok.NonNull;
import java.time.LocalDateTime;
/**
* MISSION: represent a trip that some unspecified client might want to book.
* A trip has a source location, a destination location, a departure date and
* the goods to be transported. Quantity is expressed in a unit of measure
* that is specific for the kind of goods (eg liters for liquids, tons for solids, etc.).
*/
public class Trip {
/**
* INVARIANT: each of the fields is not null and non empty
* and the date is valid
* and origin != destination and goodsQuantity > 0.
* passegero > 0
*/
private @Getter String origin;
private @Getter String destination;
private @Getter LocalDateTime departureDate;
private @Getter GoodsKind goodsKind;
private @Getter double goodsQuantity;
private @Getter double passegero; or
private double CapacitaMassima;
/**
* Creates a trip.
*
* @param origin the origin of the trip
* @param destination th
* @param departureDate t
* @param goodsKind the kind of goods to be transported
* @param goodsQuantity the quantity of goods to be transported
* @throws IllegalArgumentException if origin or destination are empty or
* goodsQuantity is not positive
*/
public Trip(@NonNull String origin, @NonNull String destination,
@NonNull LocalDateTime departureDate,
GoodsKind goodsKind, double goodsQuantity, double pasegeri, double CapacitaMassima) {
if (origin.isEmpty() || destination.isEmpty()) {
throw new IllegalArgumentException("Origin and destination must be non empty");
}
if (goodsQuantity <= 0) {
throw new IllegalArgumentException("Goods quantity must be positive");
}
if ( passegeri >= 0 && passegeri <= CapacitaMassima ) {
throw new IllegalArgumentException("Dev'essere almeno un passegero");
}
this.origin = origin;
this.destination = destination;
this.departureDate = departureDate;
this.goodsKind = goodsKind;
this.goodsQuantity = goodsQuantity;
this.passegero = passegero;
}
public String toString() {
return "Trip from " + origin + " to " + destination + " on " + departureDate + " with " + goodsQuantity + " " + goodsKind;
}
}