public class Time { public int getHour() { } public int getMinutes() { } public boolean beforeMidday() { } }
public interface Agenda { void addAppointment(Time t, String description); String getAppointment(Time t); void removeAppointment(Time t); boolean hasAppointment(Time t); ListlistAppointments(); } public class Appointment { private Time t; String description; // to complete... }
We create a SocialUser class. Each SocialUser has a name, and a set of friends (who are themselves SocialUsers). Propose an implementation. It should have a addFriend() method. Note that we suppose that if x is a friend of y, then y is a friend of x.
A relation is a friend, or a friend of a friend, etc... more precisely, friends are relations, and relations of friends are also relations. Try to use the following algorithm to implements a getRelation() method:
e= current social user stack= empty stack seen= empty set push e.friends on stack add e to seen while stack is not empty: e1= stack.pop() if (seen does not contain e1) add e1 to seen push e1.friends on stack end if end while // now, seen contains all the relations of e.