SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | /** | |
| 3 | * Predict the output of the main() method. | |
| 4 | */ | |
| 5 | public class EventList | |
| 6 | {
| |
| 7 | - | private Queue<Event> events; |
| 7 | + | // fully qualified needed for Visualizer |
| 8 | private java.util.Queue<Event> events; | |
| 9 | public EventList() | |
| 10 | {
| |
| 11 | events = new LinkedList<Event>(); | |
| 12 | } | |
| 13 | public void addEvent(Event event) | |
| 14 | {
| |
| 15 | events.add(event); | |
| 16 | } | |
| 17 | public Event getNext() | |
| 18 | {
| |
| 19 | return events.peek(); | |
| 20 | } | |
| 21 | ||
| 22 | public static void main(String[] args) | |
| 23 | {
| |
| 24 | EventList list = new EventList(); | |
| 25 | Event one = new Event("Stadium", new Date());
| |
| 26 | list.addEvent(one); | |
| 27 | Event mine = list.getNext(); | |
| 28 | System.out.println(mine); | |
| 29 | mine.setWhere("Gym");
| |
| 30 | System.out.println(list.getNext()); | |
| 31 | one.setWhere("Plaza");
| |
| 32 | System.out.println(list.getNext()); | |
| 33 | } | |
| 34 | } | |
| 35 | /** Event is something happening at a time and place */ | |
| 36 | class Event | |
| 37 | {
| |
| 38 | private String where; | |
| 39 | private Date when; | |
| 40 | /** Create the event */ | |
| 41 | public Event(String where, Date when) | |
| 42 | {
| |
| 43 | this.where = where; | |
| 44 | this.when = when; | |
| 45 | } | |
| 46 | /** The event's location is changed */ | |
| 47 | public void setWhere(String where) | |
| 48 | {
| |
| 49 | this.where = where; | |
| 50 | } | |
| 51 | /** The event's time is rescheduled */ | |
| 52 | public void setWhen(Date when) | |
| 53 | {
| |
| 54 | this.when = when; | |
| 55 | } | |
| 56 | public String toString() | |
| 57 | {
| |
| 58 | return where + ":" + when; | |
| 59 | } | |
| 60 | } |