Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Grid
- {
- int rows;
- int columns;
- ArrayList<Location> locations = new ArrayList<Location>();
- public Grid(int numRows, int numColumns)
- {
- rows = numRows;
- columns = numColumns;
- }
- public void add(int row, int column, String description)
- {
- Location point = new Location(row, column, description);
- locations.add(point);
- }
- public String getDescription(int row, int column)
- {
- int index = -1;
- for(int i = 0; i < locations.size(); i++)
- {
- if(locations.get(i).X == row && locations.get(i).Y == column)
- {
- index = i;
- }
- }
- if(index != -1)
- {
- return locations.get(index).Description;
- }
- else
- {
- return "Point not recognized";
- }
- }
- public ArrayList<Location> getDescribedLocations()
- {
- Collections.reverse(locations);
- return locations;
- }
- public class Location
- {
- int X;
- int Y;
- String Description;
- public Location(int x, int y, String description)
- {
- X = x;
- Y = y;
- Description = description;
- }
- public int getRow()
- {
- return X;
- }
- public int getColumn()
- {
- return Y;
- }
- public String getDescription()
- {
- return Description;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement