OOP2

WalkReservation.java

1
import java.util.Date;
2
3
/**
4
 * Represents a Reservation for a guided walk.
5
 * A guided walk is closely connected to a Reservation, but too different to put
6
 * them together.
7
 * 
8
 * To consider whether a guided walk was reserved by people who are doing a
9
 * Reservation, the group names in both Reservations are compared. Equal names
10
 * indicate the same people.
11
 *
12
 * If the guided walk overlaps with their reservation period, the price does not
13
 * get doubled, and vice versa.
14
 * @author Maarten Vangeneugden - 1438256
15
 */
16
public class WalkReservation {
17
18
	private String groupName;
19
	private Walk walk;
20
	private Date beginDate;
21
	private int people;
22
23
	public WalkReservation(String groupName, Walk walk, Date beginDate, int people) {
24
		this.groupName = groupName;
25
		this.walk = walk;
26
		this.beginDate = beginDate;
27
		this.people = people;
28
	}
29
30
	public WalkReservation() {
31
		this.groupName = "blank name";
32
		this.walk = null; // XXX
33
		this.beginDate = new Date();
34
		this.people = 1;
35
	}
36
37
	public void setGroupName(String groupName) {
38
		this.groupName = groupName;
39
	}
40
41
	public String getGroupName() {
42
		return groupName;
43
	}
44
45
	public void setWalk(Walk walk) {
46
		this.walk = walk;
47
	}
48
49
	public Walk getWalk() {
50
		return walk;
51
	}
52
53
	public void setBeginDate(Date beginDate) {
54
		this.beginDate = beginDate;
55
	}
56
57
	public Date getBeginDate() {
58
		return beginDate;
59
	}
60
61
	/**
62
	 * Set a new amount of people for this Walk.
63
	 * A Walk can take 10 people at most.
64
	 * @param people The new amount of people.
65
	 * @pre people must be in range [1, 10].
66
	 * @throws IllegalArgumentException if people does not meet the
67
	 * preconditions.
68
	 * @post The amount of people is updated to the given value.
69
	 */
70
	public void setPeople(int people) {
71
		this.people = people;
72
	}
73
74
	public int getPeople() {
75
		return people;
76
	}
77
78
	/**
79
	 * Determines the price for this guided walk.
80
	 * Price is determined based on the following factors:
81
	 * - 5/person/attraction
82
	 * - This, multiplied with the duration of the guided walk
83
	 * - If the group has no Reservation in the hostel during the walk, double
84
	 *   the price.
85
	 *
86
	 * For calculation of said price, the ReservationController is required.
87
	 * @param rc The ReservationController.
88
	 * @pre rc mustn't be null.
89
	 * @throws NullPointerException if rc is a null pointer.
90
	 * @return The total price of this guided Walk Reservation.
91
	 */
92
	public int getPrice(ReservationController rc) {
93
		int totalPrice = 0;
94
		totalPrice +=  (5 * this.getWalk().getAttractions().size());
95
		totalPrice *= this.getPeople();
96
		// Searching for an overlapping Reservation:
97
		for(Reservation reservation: rc.getReservations()) {
98
			if(reservation.getGroupName() == this.getGroupName() &&
99
			   this.getBeginDate().after(reservation.getBeginDate()) &&
100
			   this.getBeginDate().before(reservation.getEndDate())) {
101
				// An overlapping Reservation was found, so no extra pay
102
				return totalPrice;
103
			}
104
		}
105
		// At this point, no overlapping Reservation was found.
106
		return totalPrice * 2;
107
	}
108
}
109