└── Drill05.java /Drill05.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | 3 | public class Drill05 { 4 | 5 | // Given a list of lists of Shapes organized in a grid, 6 | // return the shape in the given row and column. 7 | public static Shape getShapeFromGrid(List> grid, int row, 8 | int col) { 9 | return grid.get(row).get(col); 10 | } 11 | 12 | // Return true if the shape in the given location is a Triangle 13 | // and false otherwise. 14 | public static boolean isTriangle(List> grid, int row, int col) { 15 | if (grid.get(row).get(col) instanceof Triangle) { 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | // Return true if the shape in the given location is a Square 22 | // and false otherwise. 23 | public static boolean isSquare(List> grid, int row, int col) { 24 | if (grid.get(row).get(col) instanceof Square) { 25 | return true; 26 | } 27 | return false; 28 | } 29 | 30 | // Concatenate all of the Strings in the grid by going row by row. 31 | // If a row or row and column location is null, then just concatenate 32 | // in an empty string. 33 | public static String byRow(List> grid) { 34 | String result = ""; 35 | for (int i = 0; i < grid.size(); i++) { 36 | if (grid.get(i) == null) 37 | continue; 38 | for (int j = 0; j < grid.get(i).size(); j++) { 39 | if (grid.get(i).get(j) == null) { 40 | result += ""; 41 | } 42 | else { 43 | result += grid.get(i).get(j); 44 | } 45 | } 46 | } 47 | return result; 48 | } 49 | 50 | // Set the given row and column in the given screen to the given character. 51 | public static void setArrayElem(char[][] screen, int row, int col, char c) { 52 | screen[row][col] = c; 53 | } 54 | 55 | } 56 | --------------------------------------------------------------------------------