<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/* A CubicleWorld is a a 2-d array of Cubicles */
public class CubicleWorld {

  private Cubicle[][] floorPlan;  //Refers to 2-d array of Cubicles
  private int rows;               //Number of rows in floor plan
  private int[] columns;          //columns[i] is # of columns in row i of floor plan

  /* Constructor: set the values of the fields */
  public CubicleWorld(int rows, int[] cols) {
    this.rows= rows;
    this.columns= cols;
    //Set 1st dimension of floor plan (number of rows)
    floorPlan= new Cubicle[rows][];
    //Set 2nd dimension of floor plan one row at a time
    for (int r=0; r&lt;rows; r++) 
      floorPlan[r]= new Cubicle[cols[r]];
  }
    
  /* Fill this CubicleWorld's floor plan */
  public void fillFloorPlan(Cubicle[] cubes) {
    for (int k=0; k&lt;cubes.length; k++) 
      floorPlan[cubes[k].row-1][cubes[k].column-1]= cubes[k];
  }
  
  /* =Get Cubicle at row r, column c.  Row, column numbers start at 1 */
  public Cubicle getCubicle(int r, int c) {
    return floorPlan[r-1][c-1];
  }
  
  /* ={Person with name s is found in this CubicleWorld}, true or false. 
   * Display the Cubicle location(s) of person(s) with name s */
  public boolean findPerson(String s) {
    boolean found= false;
    for (int r=0; r&lt;floorPlan.length; r++)
      for (int c=0; c&lt;floorPlan[r].length; c++) 
        if (floorPlan[r][c]!=null &amp;&amp; s.equals(floorPlan[r][c].name)) {
        //if (floorPlan[r][c]!=null &amp;&amp; s==floorPlan[r][c].name) {
          found= true;
          System.out.println(floorPlan[r][c]);
        }
    if (!found)
      System.out.println(s+ " not found");
    return found;
  }

  
  public static void main(String[] args) {
    
    int rows= 3;               //Number of rows of Cubicles
    int[] columns= {3, 3, 4};  //Number of columns of Cubicles
    
    //Cubicle data collected as a 1-d array
    //(Remember that Cubicle row and column numbers start at 1)
    Cubicle[] workers= new Cubicle[] { new Cubicle("Alice", 1, 1),
                                       new Cubicle("Dilbert", 1, 2),
                                       new Cubicle("Dogbert", 1, 3),
                                       new Cubicle("Ratbert", 2, 1),
                                       new Cubicle("Wally", 2, 3),
                                       new Cubicle("Asok", 3, 1),
                                       new Cubicle("Carol", 3, 2),
                                       new Cubicle("Catbert", 3, 3),
                                       new Cubicle("P-H Boss", 3, 4) 
                                     };
 
    //Create a CubicleWorld that is just big enough for all the workers 
      CubicleWorld cw= new CubicleWorld(rows, columns);
    //Now put the workers (Cubicles) into the floorPlan
      cw.fillFloorPlan(workers);
    
    //Let's test a few cases:
      System.out.println(cw.getCubicle(1,3));
      System.out.println(cw.getCubicle(2,2));
      System.out.println(cw.getCubicle(3,4));
      
      boolean foundPerson;
      foundPerson= cw.findPerson("Ratbert");
      foundPerson= cw.findPerson("Garfield");
  }
}</pre></body></html>