+1 678 648 4277 

UML Diagram of Hazard Management with C#


Hazard Control Company Assignment

Company XYZ has a hazard control model and a few employees. For the employees, there are two project leaders Chuck and Denise, and two supervisors Jack and Jeff. Jack supervises regular workers John, Mary, Jane, Tom, and Nick. Jeff supervises workers Rob, Ed, Rick, and Michael. Chuck leads workers Joe, Frank, Sam, and Greg. Denise leads workers Amy, Wil, Nancy, and Adam. Bob is the manager of Jack and Jeff, while Rachel is the manager of Chuck and Denise. The company CEO is Steve.

Let the five job titles be ranked in this hierarchical level from top to bottom as CEO, manager, project leader, supervisor, and regular worker. Each person is assigned with a head person if that person’s job title is a higher rank. In other words, the CEO has no head person and can be a legitimate head person to a lower rank direct subordinate like the manager, project leader, supervisor, or regular worker. When an employee sees a danger, the issue is reported to his/her assigned head person. If the head person is a project leader or supervisor, the person will announce the danger to all his/her direct subordinates and report it to his/her head person. If the head person is a manager, the person will gather information from all his/her direct subordinates who are project leaders or supervisors and then contact the CEO. The CEO will throw a meeting demanding all managers to come up with a set of decisions. The CEO will randomly pick one of the decisions.

Please develop a system to model the following scenario in order. John observes a gas leak of a big tank and triggers the method “void seeDanger()” to report it to his supervisor. The supervisor runs “void seeDanger()” to tell all his subordinates to perform fixIt() and also informs his manager. The fixIt() method prints out a message like “The person [name] is fixing it.” The manager runs “void seeDanger()” to handle the danger by gathering information from all supervisors under his management and executing “void contactBoss()” to inform the CEO. Each supervisor or leader has a “String provide info()” method, saying “Information from [name]”. Supervisor Jeff always sends Rob and Rick to support the other team that encounters an incidence, i.e., these two guys perform fixIt() for the other team. The CEO run “void seeDanger()” to throw a meeting to discuss with the managers, and collect suggested decisions from individual managers who perform their implemented “Decision suggestedDecision()” method. The CEO grants the final decision by the method “Decision grant(Decision[] da)”.

The CEO receives one decision from each manager. He randomly grants a decision that he receives. The doIt() method in the final decision object is invoked. The decision displays “The city’s environmental department is notified” and demands all persons in the company to evacuate. The evacuation is broadcasted from CEO to all others in a cascading style following a breadth-first search tree structure. The CEO will notify the managers in order, who will each notify their supervisors or leaders, who will each notify the regular workers under supervision. The evacuation procedure will start from the bottom up. Basically, the regular workers leave first, then the supervisors or leaders, next to the managers, and finally the CEO. Basically, a person’s evacuate() method is called to evacuate and the method displays “The person [name] is evacuating”.

Please provide the design in UML DIAGRAM and point out the applied design pattern(s).

Solution:

CEO:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class CEO: Employee { public CEO(string name_, Employee head) : base(name_, head) { } public override void fixIt() { // This function does nothing because CEO does not fix return; } public override string getJobTitle() { return "CEO"; } public override void seeDanger() { // Throws a meeting Console.WriteLine("CEO is throwing a meeting."); // Collect decisions from Managers Decision[] decisions = new Decision[2] ; int n = 0; foreach (Employee emp in getSubordinates()) { if(emp.GetType() == typeof(Manager)) { Manager manager = (Manager)emp; decisions[n] = manager.suggestDecision(); n++; } } // Grant decision Decision granted = grant(decisions); Console.WriteLine(getName() + " (" + getJobTitle() + ") chose the decision from " + granted.getCreator().getName()); // Call decision metod doIt() granted.doIt(); // Now, broadcast the evacuation evacuate(); }

Employee:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class Employee { private string name; // name of the employees private List subordinates; // list to store the subordinates for this employee private Employee head; // the head person for this employee (boss) public Employee(string name_, Employee head) { this.name = name_; this.head = head; this.subordinates = new List(); } public string getName() { return this.name; } public Employee getHead() { return this.head; } public List getSubordinates() { return this.subordinates; } public void addSubordinate(Employee sub) { subordinates.Add(sub); } public virtual void seeDanger() { } public virtual void fixIt() { } public virtual string getJobTitle() { return ""; } public virtual void notify() { } public void evacuate() { // Call the evacuate method for the subordinates foreach (Employee emp in getSubordinates()) emp.evacuate(); Console.WriteLine("The person " + getName() + " is evacuating"); } } }

Manager:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class Manager: Employee { private String gatheredInfo; public Manager(string name_, Employee head) : base(name_, head) { head.addSubordinate(this); } public String getGatheredInfo() { return gatheredInfo; } public override void fixIt() { // This function does nothing because Managers does not fix things return; } public override string getJobTitle() { return "Manager"; } public override void seeDanger() { // Now, gather information from supervisors gatheredInfo = ""; foreach (Supervisor sub in this.getSubordinates()) { gatheredInfo += sub.provideInfo() + "\n"; } Console.WriteLine(getName() + " (" + getJobTitle() + ") gathered the following information from the Supervisors:"); Console.WriteLine(gatheredInfo); // Also, tell their subordinattes to fix it foreach (Employee sub in this.getSubordinates()) { if(sub.GetType() == typeof(RegularWorker)) ((RegularWorker)sub).fixIt(); } // Finally contact boss contactBoss(); } public override void notify() { // Manager Receives a notification // Manager suns seeDanger() seeDanger(); } public void contactBoss() { getHead().notify(); // notify the head person of the Manager, which should be the CEO } public Decision suggestDecision() { Decision dec = new Decision(this, getName() + "'s (" + getJobTitle() + ") decision is: evacuate."); return dec; } } }

Project Leader:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class ProjectLeader : Employee { public ProjectLeader(string name_, Employee head) : base(name_, head) { head.addSubordinate(this); } public override void fixIt() { // Nothing because Project Leaders does not fix problems return; } public override string getJobTitle() { return "Project Leader"; } public override void seeDanger() { // Notify to its head person (manager) this.getHead().notify(); // Also, tell their subordinattes to fix it foreach (Employee sub in this.getSubordinates()) { if(sub.GetType() == typeof(RegularWorker)) // If this subordinate is a regular worker ((RegularWorker)sub).fixIt(); } } public override void notify() { // Receives a notification. return; } public string provideInfo() { return "Information from " + getName() + " (" + getJobTitle() + ")"; } } }

Regular Worker:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class RegularWorker: Employee { public RegularWorker(string name_, Employee head) : base(name_, head) { head.addSubordinate(this); } public override void fixIt() { Console.WriteLine("The person " + getName() + " is fixing it."); } public override string getJobTitle() { return "Regular Worker"; } public override void seeDanger() { // Print message Console.WriteLine(getName() + " (" + getJobTitle() + ") sees a gas leak!"); // Notify to its head person this.getHead().notify(); } public override void notify() { // Receives a notification return; } } }

Supervisor:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class Supervisor : Employee { public Supervisor(string name_, Employee head) : base(name_, head) { head.addSubordinate(this); } public override void fixIt() { Console.WriteLine("The person " + getName() + " is fixing it."); } public override string getJobTitle() { return "Supervisor"; } public override void seeDanger() { // Also, tell their subordinattes who are RegularWorker to fix it foreach(Employee sub in this.getSubordinates()) { if (sub.GetType() == typeof(RegularWorker)) ((RegularWorker)sub).fixIt(); } // Notify to its head person (manager) this.getHead().notify(); } public override void notify() { // Receives a notification // When supervisor receives an "alert", he/she sees danger seeDanger(); } public string provideInfo() { return "Information from " + getName() + " (" + getJobTitle() + ")"; } } }

Decision:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AshmeeAssignment { class Decision { private String decisionDesc; // Decision description private Employee creator; // Creator of the Decision public Decision(Employee creator, String desc) { this.creator = creator; this.decisionDesc = desc; } public Employee getCreator() { return creator; } public String getDescription() { return decisionDesc; } public void doIt() { Console.WriteLine("The city's environmental department is notified. All persons must evacuate!"); } } }

UML Diagram:

UML Diagram 1