Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * Predict the output of the main() method.
- */
- public class EventList
- {
- // fully qualified needed for Visualizer
- private java.util.Queue<Event> events;
- public EventList()
- {
- events = new LinkedList<Event>();
- }
- public void addEvent(Event event)
- {
- events.add(event);
- }
- public Event getNext()
- {
- return events.peek();
- }
- public static void main(String[] args)
- {
- EventList list = new EventList();
- Event one = new Event("Stadium", new Date());
- list.addEvent(one);
- Event mine = list.getNext();
- System.out.println(mine);
- mine.setWhere("Gym");
- System.out.println(list.getNext());
- one.setWhere("Plaza");
- System.out.println(list.getNext());
- }
- }
- /** Event is something happening at a time and place */
- class Event
- {
- private String where;
- private Date when;
- /** Create the event */
- public Event(String where, Date when)
- {
- this.where = where;
- this.when = when;
- }
- /** The event's location is changed */
- public void setWhere(String where)
- {
- this.where = where;
- }
- /** The event's time is rescheduled */
- public void setWhen(Date when)
- {
- this.when = when;
- }
- public String toString()
- {
- return where + ":" + when;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement