Many theater only provide single seat reservation and adjoing seat reservation,
single seat reservation is easy to implement, and adjoing seat reservation can
implements base on single reservation.
In this essay, I will introduce a original method to get a group of adjoining seats
. Users need to input where the seat is start and where the seat is end.
Code is as following:
import java.util.*;
/**
* This is a class represents a group of seats, each seat
* have row index and seat index.
*/
public class SeatManager
{
private String[][] seats;
private int rowNumber;
private int seatNumber;
/**
* Constractor in this class is to initialize seats
* @param row row number in this seating area
* @param seat seat number in this seating area
*/
public SeatManager(int row, int seat)
{
rowNumber =row;
seatNumber =seat;
seats= new String[rowNumber][seatNumber];
for(int i=0;i<row;i++)
{
for(int j =0;j<seat;j++)
{
seats[i][j] = "Row"+(i+1)+"Seat"+(j+1);// Every seat is represented by a String.
}
}
}
/**
* Get adjoining seats from this seats area
* @param rowStart the row index of the start seat
* @param seatStart the seat index of the start seat
* @param rowEnd the row index of the end seat
* @param seatEnd the seat index of the end seat
* @return ArrayList<String> return the object grouping of String which is demanded.
*/
public ArrayList<String> getAdjoinSeats(int rowStart,int seatStart, int rowEnd, int seatEnd)
{
ArrayList<String> seat = new ArrayList<String>();
if(rowStart == rowEnd)
{
for(int i =seatStart; i<= seatEnd; i++)
{
seat.add(seats[rowStart-1][i-1]);
}
}
else
{
for(int i=seatStart; i<= seatNumber;i++)
{
seat.add(seats[rowStart-1][i-1]);
}
for(int i =rowStart+1;i<rowEnd ;i++)
{
for(int j= 0; j<seatNumber;j++)
{
seat.add(seats[i-1][j]);
}
}
for(int i =0;i<seatEnd;i++)
{
seat.add(seats[rowEnd-1][i]);
}
}
return seat;
}
}
Then, I will interpret the method getAdjoinSeats() by giving pseudo-code:
if the start seat and end seat are in the same row
then add seats from seats[rowStart][seatStart] to seats[rowStart][seatEnd] into a arraylist
if the start seat and end seat are in different row
then add these seats in 3 steps:
1.add the started row seat into arraylist(like the above red code).
2.add the completely middle row into arraylist , need a double for loop.
3.add the end row seat into arraylist.
finally, return this arraylist to upper user.
------------------------------------------------------------------------------------------------------------
In this method, I mainly use the for loop. Here, recall the detail of for.
for (初始化 ; 条件判断 ; 操 作 ) { //code here }
其执行顺序 是:1. 初始化
2.条件判断。若正确,执行大括号中的代码,如果错误,结束循环。
3.操作。对索引值进行操作,以免是循环达到想要的次数。
4.再次条件判断(返回第二个步骤)
....... 直到条件判断不再满足,结束循环。
分享到:
相关推荐
本文探讨了在辫子群中解决共轭邻接问题的新思路,并提出了基于辫子的新签名设计。...通过这个问题,研究者设计了一种新的基于辫子的签名方案。 该签名方案在随机预言模型下被认为是高效且可证明安全的。...
adjoining structure 毗邻构筑物 adjudication fee 评估契据费用 adjusted replacement cost 经调整重置成本 administrator of estate 遗产管理人 admixture 外加剂;搀和剂 advance drainage diversion ...
In this code each SPE will synthesizes two overlap blocks to make the the area of the boundary to adjoining blocks which the other SPE synthesizes more smooth
2. **adjacent**, **adjoining** 和 **contiguous**: 都表示“紧邻”,adjacent强调地理位置接近但不一定接触,adjoining和contiguous则强调两者间有边缘或界线接触。 3. **admission** 和 **admittance**: ...
2. adjacent, adjoining, contiguous:三者都有“相邻”之意,adjacent强调地理位置上的接近,但不一定直接接触;adjoining和contiguous则强调相互接触,有边界相连。 3. admission 和 admittance:admission常用于...
- **adjoining** 和 **contiguous** 都表示“紧邻的”,通常指有边缘或界线相接,如:“The two buildings are adjoining.”(这两栋建筑是相连的) 3. **admission** 和 **admittance** - **admission** 指进入...
不同类型的房间包括"adjoining room"(相邻的房间)、"single room"(单人房)、"twin room"(双人房)、"double room"(双人房,通常有一张大床)、"triple room"(三人房,通常由两张单人床或一张双人床加一个额外...
19. Adjoining land:毗邻土地,与某地块相邻的土地。 20. Adjustment:调校,调整建筑设备或结构以达到最佳状态。 这些词汇涵盖了建筑施工、安全、材料、设备、测试和维护等多个方面,是建筑师、工程师、承包商和...
3. 动态系统:如树邻接语法(Tree-Adjoining Grammar)、词汇功能语法(LFG)、功能合一语法(CFG)和HPSG(Head-Driven Phrase Structure Grammar)。 4. 依存语法(Dependency Grammar)和配价语法(Valency ...
"ambiguous"表示模棱两可的,"adjust"则意味着调整适应,"adjoining"表示相邻的。"advocate"可以是提倡或拥护的意思,"acclaim"表示赞扬或欢呼,"accompany"则表示陪伴或伴随。 V字母的基础词汇包括"vacation"...
*7 kV ESD on LVDS I/O Pins Protects Adjoining Components:DS25BR150芯片具有7 kV静电释放保护功能,能够保护邻近组件免受静电损害。 DS25BR150芯片的应用包括: *Clock or Data Buffering / Repeating:DS25BR...
The AravallieDelhi and Satpura Mobile Belts (ADMB and SMB) and the Eastern Ghat Mobile Belt (EGMB) inIndia form major Proterozoic mobile belts with adjoining cratons and contemporary basins....
2. **Adjoining Room (邻近房)**:两间相邻并且通过内部门相连的房间,适合家庭或朋友团体。 3. **Advanced Deposit (订金)**:客人在入住前预先支付的一部分款项,用以确保房间预留。 4. **Advance Payment(预付...
- 相邻房:Adjoining room 2. 酒店术语: - 住客房(Occupied):房间已被客人占用。 - 空房(Vacant):房间已打扫干净,可供出租。 - 走客房(CO, Check out):客人已结账离开,但房间尚未打扫。 - 已清洁...
A couple of simple-structure phase modulators were used ... The laser produces pulse as short as 5.7 ps whose repetition rate tuning can cover the spacing of the adjoining order mode-locking frequencies.
- Suite/Studio suite/Adjoining room/Connecting room:不同类型的客房,如套房、公寓套房、相邻房和连通房。 - Executive Floor:行政楼层,通常提供额外的商务设施和礼遇。 - Bellboy/Concierge/Receptionist...
`adjoin`则指将事物紧密地放在一起,如房间adjoining a garden邻近花园。 此外,还有`adjustable`形容词,表示可调节的,常见于物品设计中。`administration`常用于表示管理部门或机构。`admiration`表示钦佩或赞美...
2. **相邻房间(Adjoining Rooms)**:相邻房间是指在物理位置上紧邻但不通过内部连接门相连的两个房间。这种安排适合需要隐私但仍希望保持一定联系的客人。 3. **预缴押金(Advance Deposit)**:预缴押金是酒店在客人...
2. **Adjoining Room**: 两个房间之间有门相通的连通房,方便家庭或团体客人使用。 3. **Advance Deposit**: 预付押金,客人在入住前支付的一部分房费,作为预订保证。 4. **Actual Arrival**: 实际到达酒店的时间,...
size bed(特大号床)、Queen-size bed(大号床)、Twin beds(双床房)、Single bed(单床房)、Double room(双人间)、Single room(单人间)、Suite(套房)、Studio suite(公寓套房)、Adjoining room(相邻房...