Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Question

Types of cultural maps ?

Answered: 1 week ago

Question

Discuss the various types of leasing.

Answered: 1 week ago

Question

Define the term "Leasing"

Answered: 1 week ago

Question

What do you mean by Dividend ?

Answered: 1 week ago

Question

3. Define the attributions we use to explain behavior

Answered: 1 week ago