-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelReservation.java
More file actions
138 lines (119 loc) · 4.31 KB
/
Copy pathHotelReservation.java
File metadata and controls
138 lines (119 loc) · 4.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// --== CS400 File Header Information ==--
// Name: Ethan Knifsend
// Email: Knifsend@wisc.edu
// Team: FB blue
// Role: Data Wrangler
// TA: Daniel Finer
// Lecturer: Gary Dahl
// Notes to Grader: n/a
/**
* HotelReservation represents a reservation in a hotel, containing the name of the booker, the date
* of check-in, the date of check-out, and the room number
*
* <p>
* Bugs: n/a
*
* @author Ethan Knifsend
*/
public class HotelReservation implements Comparable<HotelReservation> {
private String name;
private String checkInDate; // String that contains date in 01/01/2021 format
private String checkOutDate; // String that contains date in 01/01/2021 format
private int roomNumber;
/**
* Constructor which intializes name, checkInDate, checkOutDate, and roomNumber with inputed
* values
*
* @param name String representing the name of the person who booked this reservation
* @param checkInDate String representing the check-in date of this reservation
* @param checkOutDate String representing the check-out date of this reservation
* @param roomNumber int representing the room number of this reservation
*
*/
public HotelReservation(String name, String checkInDate, String checkOutDate, int roomNumber) {
this.name = name;
this.checkInDate = checkInDate;
this.checkOutDate = checkOutDate;
this.roomNumber = roomNumber;
}
/**
* Accessor method for name
*
* @return name String representing the name of the person who booked this reservation.
*/
public String getName() {
// TODO Auto-generated method stub
return this.name;
}
/**
* Accessor method for checkInDate
*
* @return checkInDate String representing the check-in date of this reservation.
*/
public String getCheckInDate() {
// TODO Auto-generated method stub
return this.checkInDate;
}
/**
* Accessor method for checkOutDate
*
* @return checkOutDate String representing the check-out date of this reservation.
*/
public String getCheckOutDate() {
// TODO Auto-generated method stub
return this.checkOutDate;
}
/**
* Accessor method for roomNumber
*
* @return roomNumber int representing the room number of this reservation.
*/
public int getRoomNumber() {
// TODO Auto-generated method stub
return this.roomNumber;
}
/**
* Private helper method that converts the date in "mm/dd/year" format into numerical value (int)
* that can be compared in yearmmdd format. For example, if it is given the date 01/02/2021, it
* will return an int 20210102. If this is compared to converted date 01/03/2021, it will return
* -1, as the former date is earlier than the later.
*
* @param date String representing the date in mm/dd/year format
* @return int the numerical conversion of the inputed date
*/
private int convertDate(String date) {
String day = date.substring(3, 5);
String month = date.substring(0, 2);
String year = date.substring(6);
int dayNum = Integer.parseInt(day);
int monthNum = Integer.parseInt(month);
int yearNum = Integer.parseInt(year);
return dayNum + monthNum * 100 + yearNum * 10000;
}
@Override
/**
* compareTo method which compares the check-in dates. If this check-in date is before that of the
* inputed hotel reservation, it will return a negative number. If they are the same, it will then
* compare the room numbers. If this room number is lower than that of the inputed hotel
* reservation, it will return a negative number.
*
* @param otherReservation HotelReservation being compared to this HotelReservation.
* @return int comparing the check-in date of the inputed HotelReservation and this
* HotelReservation
*/
public int compareTo(HotelReservation otherReservation) {
if (this.checkInDate.equals(otherReservation.getCheckInDate())) {
return this.roomNumber - otherReservation.getRoomNumber();
} else {
return convertDate(this.checkInDate) - convertDate(otherReservation.getCheckInDate());
}
}
/**
* toString method which returns String with information of this object
*
* @return String containing the values of the four variables held by this object
*/
public String toString() {
return name + ", " + checkInDate + "-" + checkOutDate + ", room " + roomNumber;
}
}