Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Link: http://www.cs.colostate.edu/~cs161/Fall12/labs/lab10/index.html Task: Create the class SoftwareEngineer and inherit from Employee . Implement the work() method with an appropriate print statement: who this object represents

Link: http://www.cs.colostate.edu/~cs161/Fall12/labs/lab10/index.html

Task:

  • Create the class SoftwareEngineer and inherit from Employee.
  • Implement the work() method with an appropriate print statement: who this object represents and "I am programming".
  • Implement the two SoftwareEngineer constructors: SoftwareEngineer() and SoftwareEngineer(String empName, int empId). Make sure to call their respective super class constructor.
  • Implement toString. Prefix the result of the Employee's toString with "SoftwareEngineer ".
  • Create the class SoftwareManager. You should inherit from SoftwareEngineer and implement the Manager interface.
  • Implement work() and handleCrisis() with appropriate print statements: who this object represents and "I am programming" or "handling a crisis". How many methods do you need to write?
  • Implement the two SoftwareManager constructors: SoftwareManager() and SoftwareManager(String empName, int empId). Make sure to call their respective super class constructor.
  • Implement toString. Prefix the result of the Employee's toString with "SoftwareManager ". Can you leverage the SoftwareEngineer.toString()?
  • Create the Executive class. You should inherit from Employee and implement the Manager interface.
  • Implement work() and handleCrisis() with appropriate print statements: who this object represents and "playing golf" or "handling a crisis".
  • Implement the two Executive constructors: Executive() and Executive(String empName, int empId). Make sure to call their respective super class constructors.
  • Implement toString. Prefix the result of the Employee's toString with "Executive ".
  • Implement CompanySimulator.manageCrisis(Employee emp). You may wish to test your implementation by modifying CompanySimulator.initCompany().

 public abstract class Employee { protected final String name; protected final int id; public Employee(String empName, int empId) { name = empName; id = empId; } public Employee() { name = generatedNames[lastGeneratedId]; id = lastGeneratedId++; } public String getName() { return name; } public int getId() { return id; } //returns true if work was successful. otherwise returns false (crisis) public abstract boolean work(); public String toString() { return name + " ID: " + id; } public boolean equals(Object other) { if (other instanceof Employee) { return equals((Employee)other); } return false; } public boolean equals(Employee other) { return other != null && name.equals(other.name) && id == other.id; } private static int lastGeneratedId = 0; private static String[] generatedNames = { "Leon Mcdonald", "Frankie Johnson", "Todd Rosenthal", "Mauricio Curran", "Randy Feinstein", "Donald Munoz", "Bonnie Barnhardt", "Gary Foley", "Brittney Wilson", "Lyndsay Loomis", "Madge Cartwright", "Stella Coan", "David Lafave", "Kimberly Matthews", "Dwayne Heckler", "Laura Payne", "Mary Luevano", "Walter Sizemore", "James Lawson", "Pat Nelson", "Sherry Leighton", "Anthony Tieman", "Lona Davis", "Ana Flores", "Richard Mcdonald", "Joseph Standley", "Nancy Eddy", "Joyce Shaw", "Philip Collings", "James Reay", "Barbara Acker", "Violet Cleary", "Maria Crawley", "Erin Hilton", "Evelyn Morales", "Leo Rose", "Dorothy Johnson", "Geoffrey Fogarty", "Jane Marin", "Daniel Tran", "Nancy Lee", "Peter Johnson", "Glenn Browning", "Mark Jaramillo", "Latina Gross", "Theresa Stutes", "George Thiel", "Robert Carney", "Janet Watts", "Michael English", "James Scott", "Elmer Honaker", "Brian Upton", "Dawne Miller", "Gretchen Bender", "John Carr", "Faith Gavin", "Traci Hill", "Joseph Miller", "Don Montoya", "Brandy Pritts", "Sandra Sheppard", "Charles Whitmer", "Ana Williams", "Elizabeth Murphy", "Michael Hollingsworth", "Claudine Dalton", "Harold Coleman", "Young Ayala", "Shelba Kirschbaum", "Tom Perez", "Amee Martin", "Maryanne Foote", "Sylvia Harrell", "Alexander Weibel", "Bruce Bailey", "Vincent Fidler", "Jack Wilbur", "Charles Pond", "Danielle Yocom", "John Kemp", "Jamie Casey", "Everett Frederick", "Emma Hazley", "Justin Lynch", "Tyler Miller", "Albert Reyes", "Wilbur Price", "Kimberly Halton", "Mary Underwood", "Raymond Garrett", "William Olive", "Joanne Smith", "Wilbert Howerton", "Selene Gross", "Jennie Andrews", "Jasper Barrows", "Robert Verdin", "Mark Mcallister", "Teri Morrissey" }; }

------------------------------------------------------

public interface Manager { public void handleCrisis(); }

--------------------------------------

import java.util.ArrayList; import java.util.Random; public class CompanySimulator { private int currentTime; private ArrayList company; private void initCompany() { company = new ArrayList(); company.add(new Executive()); for (int i = 0; i < 3; i++) { company.add(new SoftwareManager()); for (int j = 0; j < 2; j++) { company.add(new SoftwareEngineer()); } } } public void run(int runTime) { initCompany(); Random timeGen = new Random(); currentTime = 0; while (currentTime <= runTime) { int scheduledTime = timeGen.nextInt(10) + 1; currentTime += scheduledTime; System.out.println("Current Time: " + currentTime); performWork(); System.out.println(" "); } } private void performWork() { for (Employee emp : company) { if (!emp.work()) manageCrisis(emp); } } private void manageCrisis(Employee emp) { //TODO Implement CompanySimulator.manageCrisis } /** * @param args */ public static void main(String[] args) { CompanySimulator sim = new CompanySimulator(); sim.run(100); } }

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

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago