Page 620 - AP Computer Science A, 7th edition
P. 620

  public boolean isAisleSeat (int row, int seatNumber)
public boolean twoTogether()
public int findAdjacent(int row, int seatsNeeded)
Complete method twoTogether below.
/∗∗ Reserve two adjacent seats and return true if this was
∗ successfully done.
∗ If two adjacent seats could not be found, leave the state
∗ of the show unchanged, and return false.
∗ @return true if two adjacent seats were found, false
∗ otherwise
∗/
public boolean twoTogether()
(c) Write the Show method findAdjacent, which finds the lowest seat number in the specified row for a block of empty adjacent seats. If no such block exists, the findAdjacent method should return –1. No changes should be made to the state of the show, irrespective of the value returned.
For example, suppose the diagram of seats is as shown.
[0] [1] [2] [3] [4] [5] [0] 0 1 1 0 0 0 [1] 0 0 0 0 1 1 [2] 1 0 0 1 0 0
The following table shows some examples of calling findAdjacent for show.
 Method call Return value
  

















































































   618   619   620   621   622