Question: public abstract class Employee { protected final String name; protected final int id; public Employee(String empName, int empId) { name = empName; id = empId;
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" }; }
Lab Assignment The lab assignment will involve relatively little code writing. The main goal of this lab is to experiment with inheritance and understand how inherited methods fit into your code This lab is built around a simple discrete event simulator. Specifically, we are simulating the day to day work environment of a software development company. Suppose this company has three types of employees: executives, software engineers, and software managers (i.e. the managers of the engineers). We can represent this organization structure with the following Java class hierarchy Employee Executive SoftwareEngineer SoftwareManager You will need the following starter files Employee.java Manager.java CompanySimulator.java The Employee Abstract Class Here, we have an abstract Employee that contains code common to all of the company's employees. For example, all employees have a name, ID number, and the capacity to do work. Note that Employee.work0 method is declared abstract. This method is only a stub and does not have an implementation. This is similar to interfaces you have previously used (all methods listed in an interface are implicitly abstract) Because the Employee class is declared as abstract, Java will not allow you to instantiate Employee (example: new Employec)) Instead, we must define concrete sub-classes. A class is concrete if it is not abstract. The backdrop code, CompanySimulator, is a simple discrete event simulator. At time t, the simulator runs through an ArrayList that represents the company and tells everyone to do work by invoking Employee.work() Questions 1. Is it valid to define an abstract class that only contains fully implemented (i.e. not abstract) methods. If so, will Java let you create instances of this type? Iry 1t. 2. Justify why the work) method is abstract
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
