Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will create an online university course discussion forum. There is one forum and many subscribers. When an update to the forum is made, the
You will create an online university course discussion forum. There is one forum and many subscribers. When an update to the forum is made, the subscribers are notified. Subscribers have the option of unsubscribing when they no longer want to be notified of changes to the discussion forum public class StudentDashboard extends Observable { private int unreadMessages; public StudentDashboard() { unreadMessages = 0; } public void setUnreadMessages(int messages) { unreadMessages = messages; } public int getUnreadMessages() { return unreadMessages; } }
public class ForumMonitor implements Observer { public static final int UNREAD_ALERT_LEVEL = 0; public void update(Observable observable, Object object) { StudentDashboard messages = (StudentDashboard) observable; if (messages.getUnreadMessages() > UNREAD_ALERT_LEVEL) { System.out.println("You have " + messages.getUnreadMessages() + " unread messages."); } else { System.out.println("No unread messages found."); } } }
Please code Observer and Observable for the Observer Pattern codes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started