Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. public class Grid
  5. {
  6. int rows;
  7. int columns;
  8. ArrayList<Location> locations = new ArrayList<Location>();
  9. public Grid(int numRows, int numColumns)
  10. {
  11. rows = numRows;
  12. columns = numColumns;
  13. }
  14. public void add(int row, int column, String description)
  15. {
  16. Location point = new Location(row, column, description);
  17. locations.add(point);
  18. }
  19. public String getDescription(int row, int column)
  20. {
  21. int index = -1;
  22. for(int i = 0; i < locations.size(); i++)
  23. {
  24. if(locations.get(i).X == row && locations.get(i).Y == column)
  25. {
  26. index = i;
  27. }
  28. }
  29. if(index != -1)
  30. {
  31. return locations.get(index).Description;
  32. }
  33. else
  34. {
  35. return "Point not recognized";
  36. }
  37. }
  38. public ArrayList<Location> getDescribedLocations()
  39. {
  40. Collections.reverse(locations);
  41. return locations;
  42. }
  43. public class Location
  44. {
  45. int X;
  46. int Y;
  47. String Description;
  48. public Location(int x, int y, String description)
  49. {
  50.  
  51. X = x;
  52. Y = y;
  53. Description = description;
  54. }
  55. public int getRow()
  56. {
  57. return X;
  58. }
  59. public int getColumn()
  60. {
  61. return Y;
  62. }
  63. public String getDescription()
  64. {
  65. return Description;
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement