-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotel.java
More file actions
197 lines (183 loc) · 4.35 KB
/
Hotel.java
File metadata and controls
197 lines (183 loc) · 4.35 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package Hotel;
import java.util.*;
public class Hotel
{
Reservation d=null;
Room c=null;
String hotel_name;
public void setHotelname(String s){hotel_name=s;}
public String getHotelname(){return hotel_name;}
ArrayList<Room> room_list = new ArrayList<Room>();//ëéóôá äùìáôéùí
ArrayList<Reservation> res_list = new ArrayList<Reservation>();//ëéóôá êñáôçóåùí
public void addRooom(Room r)//ðñïóèåôåé åíá äùìáôéï óôçí ëéóôá äùìáôéùí
{
room_list.add(r);
}
public Room findRoom(int roomID)//âáæïõìå ôï êùäéêï äùìáôéïõ êáé åðéóôñåöåé ôï äùìáôéï
{
for(Room ak : room_list)
{
if(ak.getRoomNumber() == roomID)
{
c=ak;
break;
}
else
{
c=null;
}
}
return c;
}
public Reservation findReservation(int resID)//âáæïõìå ôï êùäéêï êñáôçóçò êáé åðéóôñåöåé ôçí êñáôçóç
{
for(Reservation pt : res_list)
{
if(pt.getRescode() == resID)
{
d=pt;
break;
}
else
{
d=null;
}
}
return d;
}
public boolean checkAddRes(Reservation res1, int roomcode)//âÜæïõìå ôçí êñÜôçóç êáé ôïí êùäéêü äùìáôßïõ êáé ðñáãìáôïðïéåé ôçí êñáôçóç áìá ðëçñïõíôáé ïé êáôáëëçëåò ðñïéðïèåóåéò
{
boolean q=true;
if(findRoom(roomcode)!=null)
{
if(findRoom(roomcode).add_res(res1))
{
res_list.add(res1);
q = true;
}
else
{
res1.setRoom(null);
q = false;
}
}
if(q==true)
{
System.out.println("The reservation was successful(reservation code is: " + res1.getRescode() + ")");
}
else
{
System.out.println("The reservation was not successful");
}
resissuccessful = q;
return q;
}
public boolean resissuccessful;
public int addReservation(Reservation res2) //âÜæïõìå ôçí êñÜôçóç êáé ôçí ðñïóèÝôåé óå üðïéï äùìÜôéï ìðïñåß íá ðñïóôåèåß
{
int p=0;
boolean v=true;
for(int i=0;i<room_list.size();i++)
{
res2.setRoom(room_list.get(i));
if(res2.room.add_res(res2))
{
res_list.add(res2);
System.out.println("The reservation was successful(reservation code is: " + res2.getRescode() +")");
System.out.println("Roomcode for this reservation is " + res2.room.getRoomNumber());
v=true;
for(i=res2.getArrival(); i<res2.getArrival()+res2.getResdays();i++)
{
res2.getRoom().pd[i]= res2;
}
p=res2.room.getRoomNumber();
break;
}
else
{
p=0;
v=false;
}
}
if(v==false)
{
System.out.println("The reservation was not successful");
res2.setRoom(null);
}
resissuccessful=v;
return p;
}
boolean resiscanceled;
public void reservationCancel(int reservationID) //âÜæïõìå ôïí êùäéêü ôçò êñÜôçóçò êáé áí õðÜñ÷åé óôç ëßóôá êñáôÞóåùí, ôçí áêõñþíåé
{
try
{
if(findReservation(reservationID) != null)
{
try
{
if(findReservation(reservationID).room.cancel(reservationID) && d.room.cancel(reservationID))
{
res_list.remove(d);
System.out.println("The reservation with reservation code " + reservationID + " was canceled");
resiscanceled = true;
}
else
{
System.out.println("The reservation with reservation code " + reservationID + "was not canceled");
resiscanceled=false;
}
d.room.cancel(reservationID);
}
catch(NullPointerException i){}
}
else
{
System.out.println("The reservation with reservation code " + reservationID + "was not canceled");
resiscanceled = false;
}
}
catch(ArrayIndexOutOfBoundsException n){}
}
public double incomeCalc(int roomNum1) //âáæïõìå êùäéêï äùìáôéïõ êáé åðéóôñåöåé ôá åóïäá
{
findRoom(roomNum1);
return c.pricing();
}
public double incomeCalc()// åðéóôñåöåé ôá åóïäá ïëùí ôùí äùìáôéùí
{
double total=0;
for(Room rg : room_list)
{
total = total + rg.pricing();
}
return total;
}
public void ResPlan()//åìöáíéæåé ôï ðëáíï êñáôçóåùí
{
int i;
System.out.print("ÌÝñá :\t");
for(i=1;i<=30;i++)
{
System.out.printf("%02d ", i);
}
System.out.printf("\n");
System.out.println("ÄùìÜôéï");
for(i=0;i<room_list.size();i++)
{
System.out.print(+room_list.get(i).getRoomNumber() +"\t");
for(Reservation rs : room_list.get(i).pd)
{
if(rs!=null)
{
System.out.print("* ");
}
else
{
System.out.print("_ ");
}
}
System.out.println("");
}
}
}