Web Forum
Develop the core of a program to manage a web forum. All the classes belong to package forum
.
R1 - Users
Management takes place through the facade class Forum, whose constructor receives as arguments
a string containing the web url the forum will respond at (e.g. http//www.polito.it/forum/Java/
),
and which can be retrieved through method getUrl().
To participate in the forum users must be previously registered through method registerUser()
that receives as arguments nickname, first name, last name, email address, and password.
In case the nickname is duplicated, the method must generate DuplicatedNickname exception.
The method returns a User object.
Class User provides the getter methods, getNick(), getFirst(), getLast(),
and getEmail() to read the respective attributes values.
Class Forum privides the method login() that accepts a nickname and a password
and if a user exists with matching nickname and password returns the corresponding object,
otherwise it returns null.
R2. Topic
The forum is structured into topics that can be created through method createTopic()
of class Forum receiving as arguments the name, the subject, and the user who creates it;
the method returns a Topic object. Given a topic object its characteristics can be
accessed through methods getName(), getSubject(), and getUser().
Class Forum provides the method listTopic() returning a collection of the created topics.
R3. Messages
Users can submit messages to the topics through method submitMessage() of class Topic
that receives as arguments the user, the title of the message, the body of the message and returns
a Message object.
Given a message it is possible to know title, body, user who submitted it, and topic in which
it was submitted, respectively through the methods getTitle(), getBody(), getUser(),
getTopic(). Moreover the method getTimestamp() returns the system time at which
the message was submitted (i.e. the time when the submitMessage() method was called).
Method getMessages() of class Topic returns the collection of all messages
submitted to the topic.
Hint: to get system system time use the method: System.currentTimeMillis() that returns a long.
R4. Statistics
For each user it is possible to know the number of submitted messages through method numSubmitted()
of class User. In addition the method rankUsers() of class Forum returns the collection of
all users sorted by decreasing number of submitted messages.
Method numMessages() of class Topic returns the number of messages submitted to the topic.
Method averageMessages() of class Forum returns the average number of messages submitted to all topics.