-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotel.java
More file actions
117 lines (108 loc) · 2.26 KB
/
Copy pathHotel.java
File metadata and controls
117 lines (108 loc) · 2.26 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
public class Hotel {
private String hotelName;
private Room[][] rooms;
private static int WIDTH=12;
private static int HEIGHT=6;
public Hotel()
{
rooms=new Room[HEIGHT][WIDTH];
for(int i=0;i<rooms.length;i++)
{
for(int j=0;j<rooms[i].length;j++)
{
rooms[i][j]=new Room();
rooms[i][j].setId(i+1,j+1);
}
}
}
// TODO Auto-generated constructor stub
public void setHotelName(String hotelName)
{
this.hotelName=hotelName;
}
public String getHotelName()
{
return hotelName;
}
public void searchAll()
{
for(int i=0;i<rooms.length;i++)
{
for(int j=0;j<rooms[i].length;j++)
{
System.out.print(rooms[i][j].getId()+"\t");
}
System.out.println();
for(int j=0;j<rooms[i].length;j++)
{
System.out.print(rooms[i][j].getCustomer()==null?"\t":rooms[i][j].getCustomer()+"\t");
}
System.out.println();
for(int j=1;j<=8*WIDTH;j++)
System.out.print("-");
System.out.println();
}
}
public void searchByNo(String roomNo)
{
if(testRoomNo(roomNo))
{
int height=Integer.parseInt(roomNo.substring(0,2));
int width=Integer.parseInt(roomNo.substring(2,4));
System.out.println(rooms[height-1][width-1].getCustomer()==null?"客房没有客人":roomNo+"\t"+rooms[height-1][width-1].getCustomer());
}else
{
System.out.println("没有这个客房");
}
}
private boolean testRoomNo(String roomNo) {
int height=Integer.parseInt(roomNo.substring(0,2));
int width=Integer.parseInt(roomNo.substring(2,4));
if(height<1||height>HEIGHT||width<1||width>WIDTH)
{
return false;
}else
{
return true;
}
}
public int checkIn(String roomNo,String name )
{
if(testRoomNo(roomNo))
{
int height=Integer.parseInt(roomNo.substring(0,2));
int width=Integer.parseInt(roomNo.substring(2,4));
if(rooms[height-1][width-1].in(name))
{
return 1;
}else
{
return 2;
}
}
else
{
return 3;
}
}
public int checkout(String roomNo)
{
if(testRoomNo(roomNo))
{
int height=Integer.parseInt(roomNo.substring(0,2));
int width=Integer.parseInt(roomNo.substring(2,4));
if(rooms[height-1][width-1].out())
{
return 1;
}
else
{
return 2;
}
}
else
{
return 3;//没有这个房间
}
}
}