Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. /**
  2. * Model a taxi.
  3. * @author David J. Barnes (d.j.barnes@kent.ac.uk)
  4. * @version 2017.11.06
  5. */
  6. public class Taxi
  7. {
  8. // The taxi's ID.
  9. private final int id;
  10. // The area the taxi is currently in.
  11. private int area;
  12. // Whether the taxi is free or not.
  13. private boolean free;
  14.  
  15. /**
  16. * Create a Taxi object.
  17. * @param id The taxi's ID.
  18. * @param area The area the taxi is currently in.
  19.  
  20. */
  21. public Taxi(int id, int area)
  22. {
  23. this.id = id;
  24. this.area = area;
  25. this.free = true;
  26. }
  27.  
  28. /**
  29. * Get the ID.
  30. * @return The ID.
  31. */
  32. public int getID()
  33. {
  34. return id;
  35. }
  36.  
  37. /**
  38. * Get the area.
  39. * @return the area.
  40. */
  41. public int getArea()
  42. {
  43. return area;
  44. }
  45.  
  46. /**
  47. * Return whether the taxi is free or not.
  48. * @return true if free, false otherwise.
  49. */
  50. public boolean isFree()
  51. {
  52. return free;
  53. }
  54.  
  55. /**
  56. * Set the taxi's status to being free.
  57. */
  58. public void setFree()
  59. {
  60. free = true;
  61. }
  62.  
  63. /**
  64. * Set the taxi's status to being not free.
  65. */
  66. public void setOccupied()
  67. {
  68. free = false;
  69. }
  70.  
  71. /**
  72. * Move to the given area.
  73. */
  74. public void moveTo(int area)
  75. {
  76. if(area > 0) {
  77. this.area = area;
  78. }
  79. }
  80.  
  81. /**
  82. * Get the formatted details.
  83. * @return the formatted details.
  84. */
  85. public String getDetails()
  86. {
  87. return String.format("Taxi %d is in area %d and is %sfree.",
  88. id, area, free ? "" : "not ");
  89. }
  90.  
  91. /**
  92. * Return the formatted details.
  93. * @return the formatted details.
  94. */
  95. public String toString()
  96. {
  97. return getDetails();
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement