Assignment Q4
Create a new BlueJ project called YourFirstNameLastName-A1Q4. For example, mine would be AlexHendry-A1Q4.
Create a class called LotsOfNames, that has one ArrayList field called names, which holds a collection of Strings.
Make sure you write a description of your new Class in the comments, with your name as author and give the version as the date you last worked on this exercise.
Define a constructor that initialises the ArrayList. Note that you can also add any other initialisations that you feel are relevant.
Create methods to add elements, remove elements and get the number of elements in the collection. Add a test for all three of these methods to check whether the operation was successful and print a message letting the user know if it was or was not.
Create a method called printNames. This method should loop through the collection and print out the elements (each String on a new line) as determined by the following rules:
• If the String length is less than 5, the method should print "The name " + the value of the String + " has a length less than 5". For example, if the name is Joe it would print: The name Joe has a length less than 5
• If the String starts with a, b, c, d, e, or f (either upper or lower case), the method should print "The name " + the value of the String + " starts with a, b, c, d, e, or f". For example, if the name is Daniel it would print: The name Daniel starts with a, b, c, d, e, or f
• If the String length is less than 5 and starts with a, b, c, d, e, or f (either upper or lower case), the method should print "The name " + the value of the String + " has a length less than 5 and starts with a, b, c, d, e, or f". For example, if the name is Alex it would print: The name Alex has a length less than 5 and starts with a, b, c, d, e, or f
• If none of the above criteria is met, then the method should print the String element in uppercase. For example, if the name is Jimmy, it would print: JIMMY
Once you have finished your project, open the terminal window in BlueJ and turn on record method calls. Create a new LotsOfNames object, and then add at least ten (10) Strings using the add method you wrote. You must have:
• A String that has a length that is less than 5
• A String that starts with a, b, c, d, e, or f
• A String that has a length that is less than 5 and starts with a, b, c, d, e, or f
Demonstrate removing an element using the remove method you wrote, and then find the number of elements using the method you wrote that gets the number of elements. Finally, run your printNumbers method.
Copy all your calls into a text file called YourFirstNameLastName-A1Q4-exampletxt. For
example, mine would be AlexHendry-A1Q4-example.txt and save it in your BlueJproject
folder.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.