Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public interface Monitor { public void update(String state); } // Subject Interface public interface GrassCuttingMachine { public void register(Monitor monitor); public void unregister(Monitor monitor); public

public interface Monitor { public void update(String state); } // Subject Interface public interface GrassCuttingMachine { public void register(Monitor monitor); public void unregister(Monitor monitor); public void notifyObservers(String state); } // Simple Monitor public class SimpleMonitor implements Monitor { @Override public void update(String state){ System.out.println("Simple Monitor: The grass-cutting machine needs repair: " + state); } } // Medium Monitor public class MediumMonitor implements Monitor { @Override public void update(String state){ System.out.println("Medium Monitor: The grass-cutting machine needs repair: " + state); } } // Advanced Monitor public class AdvancedMonitor implements Monitor { @Override public void update(String state){ System.out.println("Advanced Monitor: The grass-cutting machine needs repair: " + state); } } // Concrete Subject public class CuttingMachine implements GrassCuttingMachine { private List monitors = new ArrayList<>(); @Override public void register(Monitor monitor) { monitors.add(monitor); } @Override public void unregister(Monitor monitor) { monitors.remove(monitor); } @Override public void notifyObservers(String state) { for (Monitor monitor : monitors) { monitor.update(state); } } } // Client public class Main { public static void main(String[] args) { GrassCuttingMachine grassCuttingMachine = new CuttingMachine(); SimpleMonitor simpleMonitor = new SimpleMonitor(); grassCuttingMachine.register(simpleMonitor); grassCuttingMachine.notifyObservers("WORKING-NORMALLY"); grassCuttingMachine.notifyObservers("MINOR-REPAIR-NEEDED"); MediumMonitor mediumMonitor = new MediumMonitor(); grassCuttingMachine.register(mediumMonitor); grassCuttingMachine.notifyObservers("MAJOR-REPAIR-NEEDED"); grassCuttingMachine.notifyObservers("HARD-TO-FIX"); AdvancedMonitor advancedMonitor = new AdvancedMonitor(); grassCuttingMachine.register(advancedMonitor); grassCuttingMachine.notifyObservers("TOTALLY-BROKEN"); } }

Please draw UML class diagram for the above code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the importance of financing for entrepreneurial success.

Answered: 1 week ago

Question

Question How are IRAs treated for state tax law purposes?

Answered: 1 week ago