Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a New Class named Company to store the employee mappings of employee names (Key) to employee ids (Value) Declare and initialize class constants MIN

Create a New Class named Company to store the employee mappings of employee names (Key) to employee ids (Value)

Declare and initialize class constants MIN and MAX to appropriate values

Declare and instantiate a Random randomGenerator field object

Declare a String field named name for the companys name

Declare a HashMap field named employees

Add a constructor with only 1 parameter named name and:

Assign name field to name parameter after trim, uppercase & replaceAll (1 or more ANY white space regular expression with just 1 single space)

Initialize employees field by creating an instance of that object

Add accessors getName( ) and getEmployees( )

Add accessor getTotalNumberEmployees( ) to return the total number of mappings in the collection of the employees field

Add formatString(String origString) to return a formatted origString after trim, uppercase, and replaceAll in between white spaces (with single space)

MUST first check if origString is null (which just returns an empty String)

Add method 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)

MUST .split the parameter name into a String[ ] nameArray with regex taking into account multiple white spaces in between words in name

MUST use a for loop to get the first letter in each word in nameArray

MUST use class constants MIN & MAX (NO hard-code) to generate (using .nextInt) the random number used for the id in the range [MIN MAX]

Add addEmployee(String inputName) & removeEmployee(String inputName) both with void returns and:

Check if (trimmed) inputName is empty or null, print Name is INVALID

MUST use formatString for inputName (remember Strings are immutable)

MUST use .containsKey to see if inputName key exists in employees and:

Print Existing: (if name already exists for addEmployee)

OR Non-existing: (if non-existing for removeEmployee)

MUST use generateId (for addEmployee) to generate employee id to .put

MUST print heading with name & id, if employee add/delete is successful

Add void removeIds(String id) to remove ALL mappings in employees where the value matches the id search parameter and:

MUST use a local variable to keep track if a match was found

MUST also have check if id parameter is null or empty

MUST use formatString to format the id input parameter

MUST use a for loop, .keySet and .iterator to iterate thru all employees

Check if each employee id value is equal (ignoring case) to the search id

MUST use the Iterator.remove to remove id matching mappings

MUST print heading with name & id for EACH removed employee

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

Add void listEmployees() to print ALL employee names (Key) & ids (Value):

MUST always print the heading Employees for :

MUST use getTotalNumberEmployees or .isEmpty to check if NO entries in employees exist and printsNO employees

MUST use a for-each loop and .keySet to iterate thru all employees

MUST print employee in format : (w/ leading spaces)

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

More Books

Students also viewed these Databases questions