Question: Use Javadoc documentation standards (comments & tags) and good programming style (10) Suppose a Company class has a name of String object type and group

Use Javadoc documentation standards (comments & tags) and good programming style (10)

Suppose a Company class has a name of String object type and group (collection) of employees where each employee name (Key) is mapped to an employee id (Value):

The employee name of String object type is always stored in uppercase with ALL extra spaces (leading, trailing and multiples spaces in the string) removed

The employee id of String object type is the first letter of each word in the name along with a random 3-digit number between 100 999 (inclusive of both ends) (e.g., ! <"WAYNE LAWTON", "WL123">) Create a new project, Company, in BlueJ. Create a class Company with the fields described above. (2) Complete the Company class following the instructions below:

Declare and initialize class constants MIN = 100 and MAX = 999. (1)

Declare a Random randomGenerator field. (1)

Define a constructor that takes one parameter named name and (3) Assign name parameter to name field (HINT: use String methods .trim, .toUppercase & re- placeAll (replace 1 or more ANY white space regular expression with just 1 single space)) Initialize employees field by creating an instance of that object Initialize randomGenerator field by creating an instance of that object

Define accessor methods getName() and getEmployees() to return the appropriate fields. (2)

Define an accessor method getTotalNumberEmployees() to return the total number of mappings in the collection of the employees field. (1)

Define a method with the header private String formatString(String origString) to return a for- matted origString after applying .trim, .toUppercase, and .replaceAll in between white spaces (with single space) to origString. (HINT: MUST first check if origString is null (which just returns an empty String)) (2)

7. Define a method with the header private String generateId(String name) to return the employee id generated by taking the first letter of each word in name parameter AND adding a random 3-digit integer between 100-999 (inclusive of both ends) (4)

.split the parameter name into a String[ ] nameArray and take into account multiple white spaces in between words in name

use a for-each loop for (String word: nameArray) {

...

}

and .substring(0,1) to get the first letter in each word in nameArray

use class constants MIN & MAX (NO hard-code) to generate (using .nextInt) the 3-digit random number in the range [MIN MAX] 8. Define two methods with headers public void addEmployee(String inputName) & public void removeEmployee(String inputName) to add and remove into/from the collec- tion (8): Check if (trimmed) inputName is empty or null, print Name is INVALID Else use formatString for inputName (remember Strings are immutable) use .containsKey (from HashMap) to see if inputName key exists in employees. for addEmployee: if key already exists, print out an error message and do not add item for removeEmployee: if key does not exist, print out an error message and do not remove item To add employee: use generateID to generate employee id to .put into collection. To remove employee: use .remove (from HashMap). print a message when adding and removing an item from the collection is successful. 9. Define a method with header public void removeIds(String id) to remove ALL mappings in em- ployees where the value (NOT key) matches the id search parameter. (6) use a local variable to keep track if a match was found check if id parameter is null use formatString to format the id input parameter use a for/while loop, .keySet and .iterator to iterate through employees Check if each employee id value is equal (ignoring case) to the id search parameter use the Iterator.remove to remove mappings matching the id print the name & id for EACH removed employee

after the entire search is completed (outside of loop), check if no matches found, then print NO employees with id: ( is the id parameter)

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!