Create a class called LotsOfNames, that has one ArrayList field called
Ask Expert

Be Prepared For The Toughest Questions

Practice Problems

Create a class called LotsOfNames, that has one ArrayList field called

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.

Hint
ComputerA text file is a computer file that is structured as a sequence of lines that only contains text and has no special formatting. It is a type of digital file that contains letters, numbers, and symbols, or a combination of all that enables the creation and storage of text without any special formatting....

Know the process

Students succeed in their courses by connecting and communicating with
an expert until they receive help on their questions

1
img

Submit Question

Post project within your desired price and deadline.

2
img

Tutor Is Assigned

A quality expert with the ability to solve your project will be assigned.

3
img

Receive Help

Check order history for updates. An email as a notification will be sent.

img
Unable to find what you’re looking for?

Consult our trusted tutors.

Developed by Versioning Solutions.