Question: Create a new BlueJ project using BlueJ Create a class called VeggieBasket, that has one ArrayList field called vegetables, which holds a collection of Strings.

"Create a new BlueJ project using BlueJ
Create a class called VeggieBasket, that has one ArrayList field called vegetables, which holds a collection of Strings. Define a constructor that initialises the ArrayList. Note that you can 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. Make sure you add tests for errors and sensible error messages. Create a method called printVeggies. This method should loop through the collection and print out the elements (each String on one line) as determined by the following rules; If the vegetables has a total letter less than 6, instead of printing the vegetable name, it should print Gollum. If the vegetable starting letter begin with a vowel, instead of printing the vegetable name, it should print Frodo. If both conditions above are satisfied, it should print Legolas. If none of the prior criteria are met, then the method should print Gandalf. Write a m XD16 ethod countNames that prints each name that appeared with its total counts. (e.g. Gollum:2, Frodo:3, Legolas:1, Gandalf:4) Once you have finished your project, clear the terminal window in BlueJ and record the following. Add at least ten (10) Vegetables inside the ArrayList using the add method you wrote. You must have vegetables that satisfy all of the printVeggies conditions. Demonstrate removing an element using the remove method you wrote, and then find the number of elements using your method. Finally, run your printVeggies method."

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!