You are going to make an application that stores names in a String array with the following format: “Erik Svensson” -> “[first name][whitespace][last name]”.
You may add any number of private helper methods. Remember to keep it simple with focused methods during the workshop.
You may not use Collections (List, Set, Map…etc.), Stream API, or any kind of helper besides the Arrays class when doing this workshop.
-
Create a new class called
NameRepository. -
Inside
NameRepository, create a private static empty array of String callednames. -
Define the following methods:
public static int getSize()
- Returns the number of elements in the array.
public static void setNames(String[] names)
- Sets the private static array. This should replace all existing names.
public static void clear()
- Should completely empty the array.
public static String[] findAll()
- Returns all names in a new array.
-
Define the following methods in
NameRepository:public static String find(final String fullName)
- Returns the name if found and
nullif not found.
public static boolean add(final String fullName)
- Should add a new name to the array. Returns
truewhen the name was added andfalsewhen the array contains the name.
- Returns the name if found and
-
Define the following methods in
NameRepository:public static String[] findByFirstName(final String firstName)
- Searches the array trying to find all names that have the passed-in first name. Returns a String array containing all matches.
public static String[] findByLastName(final String lastName)
- Searches the array trying to find all names that have the passed-in last name. Returns a String array containing all matches.
public static boolean update(final String original, final String updatedName)
- Should find a name and replace it with the new
fullNameif available. Returnstrueif the name was found and updated with the new name. Returnsfalseif the name could not be updated because the name wasn’t found or the name was found but an existing name matching theupdatedNamealready exists.
-
Define the following method in
NameRepository:public static boolean remove(final String fullName)
- Should remove a name from the array. Returns
trueif the name was removed andfalseif the name was not removed for some reason.
- Should remove a name from the array. Returns
Lin to Access the Workshop_ArrayPart1.pdf
Lin to Access the Workshop_ArrayPart2.pdf
Lin to Access the Workshop_ArrayPart3.pdf
Lin to Access the Workshop_ArrayPart4.pdf