Given a list of lists of Shapes organized in a grid, return the
shape in the given row and column.? For two shapes, square and
rectangle
public static Shape getShapeFromGrid(List<List<Shape>>
grid, int r, int c) {
}
Return true if the shape in the given location is a Square and
false otherwise.
public static boolean isSquare(List<List<Shape>> grid,
int r, int c) {
return false;
}
public class Shape {
public double area() {
return 0;
}
public String toString() {
return "Shape base class";
}
}
CODE
public static Shape getShapeFromGrid(List<List<Shape>> grid, int r, int c) {
if (r >= grid.size() || c >= grid.get(r).size()) {
return null;
}
return grid.get(r).get(c);
}
public static boolean isSquare(List<List<Shape>> grid, int r, int c) {
if (r >= grid.size() || c >= grid.get(r).size()) {
return false;
}
Shape s = grid.get(r).get(c);
return s.getLength() == s.getWidth();
}
NOTE: Since you have not provided the full definition of Shape class, I have the provide the implementation of isSquare() assuming that Shape class has functions getLength() and getWidth(),
Get Answers For Free
Most questions answered within 1 hours.