Page 621 - AP Computer Science A, 7th edition
P. 621
show.findAdjacent(0,3) show.findAdjacent(1,3) show.findAdjacent(2,2) show.findAdjacent(1,5)
Complete method findAdjacent below.
3
0 or 1
1 or 4 –1
/∗∗ Return the lowest seat number in the specified row for a
∗ block of empty adjacent seats. If no such block exists,
∗ return –1.
∗ @param row the row number
∗ @param seatsNeeded the number of adjacent empty
seats needed
∗ @return lowest seat number for a block of needed
adjacent
∗ seats or –1 if no such block exists ∗/
public int findAdjacent(int row, int seatsNeeded)
2. A company sends a form letter to all of its potential customers. In order to personalize each letter, various tokens (symbols) in the form letter are replaced by either the customer’s name, city, or state, depending on the token. A customer can be represented by a Customer class, whose partial implementation is shown below.
public class Customer {
private String name; private String city; private String state;
/∗ ∗ @return the name public String getName() { return name; }
/∗ ∗ @return the city of this
∗ / ∗ /
of this
customer
customer