Guest User

Prediction Exercise - Ch 3

a guest
Jan 20th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Predict the output of the main() method.
  4. */
  5. public class EventList
  6. {
  7. private Queue<Event> events;
  8. public EventList()
  9. {
  10. events = new LinkedList<Event>();
  11. }
  12. public void addEvent(Event event)
  13. {
  14. events.add(event);
  15. }
  16. public Event getNext()
  17. {
  18. return events.peek();
  19. }
  20.  
  21. public static void main(String[] args)
  22. {
  23. EventList list = new EventList();
  24. Event one = new Event("Stadium", new Date());
  25. list.addEvent(one);
  26. Event mine = list.getNext();
  27. System.out.println(mine);
  28. mine.setWhere("Gym");
  29. System.out.println(list.getNext());
  30. one.setWhere("Plaza");
  31. System.out.println(list.getNext());
  32. }
  33. }
  34. /** Event is something happening at a time and place */
  35. class Event
  36. {
  37. private String where;
  38. private Date when;
  39. /** Create the event */
  40. public Event(String where, Date when)
  41. {
  42. this.where = where;
  43. this.when = when;
  44. }
  45. /** The event's location is changed */
  46. public void setWhere(String where)
  47. {
  48. this.where = where;
  49. }
  50. /** The event's time is rescheduled */
  51. public void setWhen(Date when)
  52. {
  53. this.when = when;
  54. }
  55. public String toString()
  56. {
  57. return where + ":" + when;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment