Question: Task 1: Implement the Missing Code * Employee.java * `equals()` * SoftwareEngineer.java * `doWork()` * `toString()` * Add the job title to supers `toString` method's

Task 1: Implement the Missing Code

* Employee.java

* `equals()`

* SoftwareEngineer.java

* `doWork()`

* `toString()`

* Add the job title to supers `toString` method's value.

* SoftwareManager.java

* Also includes the additional method `fixProblem()`.

* Essentially the same as Software Engineer, but with a different name.

* Executive.java

* `toString()`

* Add the job title to supers `toString` method's value.

* CompanySimulator.java

* Constructor method

* `initCompany()`

* Add SoftwareEngineer's and SoftwareManager's to the company.

* `handleProblem()`

public abstract class Employee { private String name; private int id;

public Employee() { name = ""; id = -1; }

public Employee(String name, int id) { this.name = name; this.id = id; }

public String getName() { return name; }

public int getId() { return id; }

public abstract boolean doWork();

public String toString() { return name + ", ID: " + id; }

public boolean equals(Object o) { System.out.println("Incomplete - implement me"); return false; } }

import java.util.Random;

public class SoftwareEngineer extends Employee { public SoftwareEngineer() { super(); }

public SoftwareEngineer(String name, int id) { super(name, id); }

public boolean doWork() { Random rand = new Random();

System.out.println("Incomplete - implement me"); // get a random number between 0 and 99 // if it's less than 10 // print "I broke something..." // return false // otherwise // print "I am programming." // return true

return true; }

public String toString() { System.out.println("Incomplete - Implement me"); return ""; } }

public class Executive extends Employee implements Manager { public Executive() { super(); }

public Executive(String name, int id) { super(name, id); }

public boolean doWork() { System.out.println("Playing golf..."); return true; }

public void fixProblem() { System.out.println("You pulled me away from golf for this?"); }

public String toString() { System.out.println("Incomplete - implement me"); return ""; } }

public class CompanySimulator { private ArrayList employees = new ArrayList<>();

// Randomly generated from some website... 24 in total private String[] randomNames = { "Dolores Dunn", "Sadie Lambert", "Ed Vega", "Kristin Rose", "Tommie Burns", "Devin Newman", "Norma Page", "Rafael Willis", "Esther James", "Matt Garcia", "Brendan Gilbert", "Gail Rowe", "Sabrina Hamilton", "Gwendolyn Harrison", "Mack Osborne", "Leon Moody", "Derek Carter", "Garrett Lowe", "Bridget Fox", "Donnie Hampton", "Clinton Mclaughlin", "Tami Erickson", "Sonja Peterson", "Marian Lawrence"};

public CompanySimulator() { System.out.println("Incomplete - implement me"); // call initCompany // call displayEmployees }

public void initCompany() { // Hire people, assign Manager/Software Engineer positions

// Let's start by adding the CEO employees.add(new Executive("Kevin Scrivnor", 1));

// Add the rest based on the index of i. for (int i = 0; i < randomNames.length; i++) { int id = i + 2; String name = randomNames[i];

// if the i is divisible by 6, add a new manager // otherwise, add a software engineer } }

public void displayEmployees() { System.out.println("Displaying the employees:"); // Print out the list of employees for (Employee e : employees) { System.out.println(e); } System.out.println(""); }

public void performWork() { for (Employee e : employees) { System.out.print(e.getName() + ": "); boolean res = e.doWork(); if (!res) { handleProblem(e); } } }

public void handleProblem(Employee e) { System.out.println("Incomplete - implement me");

// if the employee is a Software Engineer // Print "Looks like [name] broke something. Looking for their manager..." // get the index of the the employee from the employees ArrayList // starting from that index, while you haven't found a mananger // keep looking backwards (lower indexes) till you find one

// Now that you have found their manager, the manager should fix the problem

// otherwise, if the employee is a SoftwareManager then // the executive should fix the problem. }

public void simulate(int time) { int currentTime = 0; Random rand = new Random(); while (currentTime < time) { int timeIncrease = rand.nextInt(10) + 1; currentTime += timeIncrease;

System.out.println("Current time: " + currentTime); performWork(); System.out.println(""); } }

public static void main(String[] args) { CompanySimulator cs = new CompanySimulator(); cs.simulate(100); } }

SoftwareMananger.java

//Implement me

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!