Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:28:06+00:00 2026-06-02T07:28:06+00:00

My home work assignment is to figure out: What this code does What potential

  • 0

My home work assignment is to figure out:

  • What this code does
  • What potential problems there are

Code

/// Enum
public enum Event {
    TORNADO, THUNDERSTORM, TSUNAMI, RAIN, SNOW, WIND, COLD, HEAT; 
    public final static String CRITICAL = "Critical";
    public final static String SEVERE = "Severe";
    public final static String MEDIUM = "Medium";
    public final static String LIGHT = "Light";

    private String severity;
    private String location;

    public void setSeverity(String severity) {
        this.severity = severity; 
    }

    public void setLocation(String location) {
        this.location = location; 
    }

    public String toString() {
        return super.toString() + ":" + severity + " at " + location; 
    }
}

///Interface
public interface IEventListener {
    void eventReceived(Event event); 
}

///Class
public class EventPublisher implements IEventListener {
    Map<Event, Collection<IEventListener>> listeners = new HashMap<Event, Collection<IEventListener>>(); 

    @Override 
    public synchronized void eventReceived(Event event) {
        for (IEventListener listener : listeners.get(event)){ 
            listener.eventReceived(event); 
        }
    }

    public synchronized void register(IEventListener listener, Event event){
        Collection<IEventListener> list = listeners.get(event); 
        if (list == null) {
            list = new LinkedList<IEventListener>();
            listeners.put(event, list); 
        }
        list.add(listener);
    }

    public synchronized void deregister(IEventListener listener, Event event) {
        listeners.get(event).remove(listener); 
    }

    public String toString() {
        String ret = ""; 
        Iterator<Event> i = listeners.keySet().iterator();
        while (i.hasNext()) {
            Iterator<IEventListener> j = listeners.get(i.next()).iterator();
            while (j.hasNext()) {
                ret = ret + i.next() + "::" + j.next() + "\n"; 
            }
        }
        return ret; 
    }
}

I went through the code and figured out that this code tries to produce the weather report and classify the weather condition based on eventReceived (Event can be registered/deRegistered).

I however cannot see any problems with the code. My teacher insists that there are issues. Can anyone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:28:12+00:00Added an answer on June 2, 2026 at 7:28 am

    First of all, Event should not be an enum. Since its members are effectively singletons; by changing the e.g. severity of one TORNADO, you’d change the severity of all of them. You should have an enum for EventType, one for Severity, and an Event class that uses them.

    Then, your map inside the event publisher will change…

    Also, the deregister method could throw a null reference exception…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with this home work assignment. I can handle the syntax,
I am working on a homework assignment and I'm trying to figure out a
Can Config::Simple work with properties file with variable assignment, e.g.: server_name=myapp.com home_url=${server_name}/home/index.html login_url=${server_name}/login/
So first off, this is a homework assignment, so please don't write any code
I'm working on a home work assignment. The question is: Write an awk script
I have a homework assignment to sort an array in ascending order. Obviously, this
I'm doing a homework assignment in which I need to print out to the
This was a homework assignment for my students (I am a teaching assistant) in
I have this homework assignment where the user is asked to input numbers and
This is my second week of learning python and I got an homework assignment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.