-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelGuest.java
More file actions
116 lines (98 loc) · 3.51 KB
/
HotelGuest.java
File metadata and controls
116 lines (98 loc) · 3.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
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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class HotelGuest {
// [GUEST_NAME, ROOM_NUMBER, ROOM_TYPE, NIGHTLY_COST, DURATION, TOTAL_COST] \\
private String guestName; // Name of Guest.
private String room; // Room of Guest
private String roomType; // Room Type of Guest
private int nightlyCost; // Nightly Cost of Room Type
private int duration; // Duration of Stay for the Guest
private int totalCost; // Total Cost of Stay
public HotelGuest(String name) {
try {
File hotelData = new File(
"C:\\Users\\306972\\Desktop\\AP CSA\\HotelManagementDataBaseProject\\HotelData.csv"); // Gets File
BufferedReader in = new BufferedReader(new FileReader(hotelData)); // Like Scanner. Easier to use while File Reading
String line;
while ((line = in.readLine()) != null) { // While current line is not equal to null
String[] fields = line.split(","); // Seperate the line into a String array. Seperate at the commas.
if (fields[0].equals(name)) { // If the name matches the name in the constructor, initialize all the variables with those attributes
this.guestName = fields[0];
this.room = fields[1];
this.roomType = fields[2];
this.nightlyCost = Integer.parseInt(fields[3]);
this.duration = Integer.parseInt(fields[4]);
this.totalCost = Integer.parseInt(fields[5]);
break; // When Guest is found, break out of loop. (For efficiency)
}
}
in.close();
} catch (Exception e) {
System.out.println(e);
}
}
/**
* Gets the name of the Guest
* @return The Guest name stored in the database
*/
public String getGuestName() {
return guestName;
}
public void setGuestName(String guestName) {
this.guestName = guestName;
}
/**
* Gets the room number of the Guest
* @return Room Number from Database
*/
public String getRoom() {
return room;
}
public void setRoom(String room) {
this.room = room;
}
/**
* Gets the room type of the Guest
* @return Room Type from the database
*/
public String getRoomType() {
return roomType;
}
public void setRoomType(String roomType) {
this.roomType = roomType;
}
/**
* Gets the nightly cost of the room
* @return The Nightly Cost from the Database
*/
public int getNightlyCost() {
return nightlyCost;
}
public void setNightlyCost(int nightlyCost) {
this.nightlyCost = nightlyCost;
}
/**
* Gets the stay time/duration of the Guest
* @return The Duration from the database
*/
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
/**
* Gets the total cost of the Guest's stay
* @return The calculated total cost from the database
*/
public int getTotalCost() {
return totalCost;
}
public void setTotalCost(int totalCost) {
this.totalCost = totalCost;
}
public String toString() {
return "Name: " + this.guestName + "\nRoom: " + this.room + "\nRoom Type: " + this.roomType + "\nNightly Cost: " + this.nightlyCost + "\nDuration: " + this.duration + "\n\nTotal Cost: " + this.totalCost;
}
}