Question: IN JAVA The goal of this assignment is to implement a program that generates personalised lists of plants for a new Botanic Garden that you

IN JAVA The goal of this assignment is to implement a program that generates personalised lists of plants for a new Botanic Garden that you have been tasked with planning. It takes an input word (e.g. a persons name) as its argument and creates a list of plants in which the first let- ter(s) of each plant spell the given word. For instance, the program could run as follows: $ java GardenPanner Tommy Thimbleberry Ole monkey-face (orchid) Manna gum (very tall tree) Massachusetts bearberry Yellow indian shoe (orchid) Once you have completed Question 4, it should also be possible to specify that the program should allow multiple letters from the input word to start each plant. This is done by supplying a second numerical argument: $ java GardenPlanner Dominique 3 DOgwood Moon set (orchid) Ivory pam tree (tall tree) NInebark QUEen of the angraecums (orchid) The words used for each character or character sequence are randomly chosen from some given lists, and multiple runs can produce different results: $ java Recipe Dominique 3 Dogwood One day flower (orchid) Mengaris (very tall tree) INdigofera Indian crocus (orchid) QUiver tree (small tree) Elderberry Three plant lists with shrubs, orchids, and trees are available for download on Moodle. You should store these files in the same directory as your Java code. You will need several methods of the Java API for this assignment. The best resource for help on how to invoke a method or use an object is the official API documentation at http://docs. oracle.com/javase/8/docs/api/.

1 GardenItemStore Data Structure. The garden planner relies on the GardenItemStore class for mapping se- quences of one or more characters to lists of plants. Mathematically, the structure corre- sponds to a partial function from strings to sets of strings. Create a GardenItemStore class that maintains a map of type Map> internally. Write the following constructors and methods: * a constructor GardenItemStore() that takes no arguments and initialises the map using a new HashMap; * a method boolean containsKey(String key) that checks whether the map contains a given string as a key; * a method void put(String key, String plant) that creates a new mapping from key to plant (note that it should not overwrite existing mappings but add to them); * a method String getRandomItem(String key) that looks up key in the map and re- turns a random plant (using the Random class) from the list of strings that key is mapped to. In the result, the letters corresponding to key should be capitalised to achieve an ef- fect like in the overview above. If key is not mapped to any words, the method should return null.

Your Own Testing Class. Now write a your own tests for your new class. Create a class GardenItemStoreTest with a main method that initialises a variable store with a new instance of GardenItemStore. Add to the GardenItemStore a number of mappings from one or two characters to multiple different words, e.g. store.put("a", "azalea"); store.put("ba", "burning bush"); store.put("ba", "bursting heart"); store.put("a", "amur chokecherry");Add code to retrieve multiple random words for those keys using getRandomItem. Also check that null is returned for non-existent mappings.

2 Populating the GardenItemStore Loading the Plant Lists. Declare a second constructor for GardenItemStore that takes afile name as an argument and loads a list of plants into the map using the class BufferedReader. This constructor should be declared to throw IOException, which signals that it could not suc- cessfully load the file. Make sure to call close() on the BufferedReader within the construc-tor, even in the event of an exception being thrown, by using an appropriate finally block or try-with-resources statement. Each line in the item list is a single plant. You should fill the map such that the initial character of each plant maps to the full plant name. Ensure that your code is case-insensitive. You should do this by converting all inputs to lower case before adding them to the store.

OrchidStore and TreeStore. To make the output of your program more helpful, you should indicate to the user that the plants from the file orchids.txt are orchids, and how big the trees in the trees.txt file are. Write specialised classes OrchidStore and TreeStore that inherit from GardenItemStore. These classes should override getRandomItem to achieve the following. * For orchids, your program should append the following text to the plant name: (orchid). * Each item in the list of trees consists of a tree name and its maximum height in metres, separated by a space. If the height is over 80 metres, it is considered a very tall tree; otherwise, if the height is over 15 metres, it is considered a tall tree; otherwise, it is con- sidered a small tree. Your program should output the name of the tree, followed by one of (very tall tree), (tall tree), or (small tree), as appropriate. So, you will have to split the string into the part containing the tree name and the part containing the height (minus the suffix m for metres), then convert the height to an integer in order to append the correct text to the tree name. (careful: some of the tree names already contain spaces!)

3 Creating Garden Plans Generating. Create a new class GardenPlanner that does the actual generation of lists ofplants to include in your garden. It should load a GardenItemStore for the shrubs, an OrchidStore for the orchids, and finally a TreeStore for the trees. Add a method List generate(String input) that iterates through a string, looking up characters in the different GardenItemStore objects and adding the resulting words to a list of strings that is then returned as the result. Structure your code elegantly, use any addi- tional methods you think are appropriate, and avoid duplicating code. To ensure balanced plans are generated you should ensure that: a plan with at least one plant includes at least one shrub; a plan with at least two plants includes at least one orchid; a plan with at least three plants includes at least one tree; and a plan includes at least as many orchids as trees. Input Processing. Add a main method to GardenPlanner that takes the word given as the first command line argument and prints the resulting plan line by line. Make sure to handle any exceptions properly. Test your code by running your program with several words as in-puts.

examples for list of plants and trees that need to be called in code by putting them in the same directory as the code:IN JAVA The goal of this assignment is to implement a program

Alder 20m Alpine ash 88m Ash 40m Aspen 30m Bird cherry 15m Blackthorn 5m Brown top stringbark 88m Carolina Silverbell 13m Chaste Tree 3m Coast Douglas-fir 100m Coast redwood 116m Crab apple 10m Crape Myrtle 8m Dinizia excelsa 88m Dog rose 2m Downy birch 15m Elder 5m Entandrophragma excelsum 81m Flowering Dogwood 10m Fringe Tree 6m Giant sequoia 96m Goat willow 10m Golden Chain Tree 10m Grand fir 81m Grey willow 10m Guelder rose 5m Hawthorn 15m Hazel 15m Holly 10m Hopea nutans 83m Alder 20m Alpine ash 88m Ash 40m Aspen 30m Bird cherry 15m Blackthorn 5m Brown top stringbark 88m Carolina Silverbell 13m Chaste Tree 3m Coast Douglas-fir 100m Coast redwood 116m Crab apple 10m Crape Myrtle 8m Dinizia excelsa 88m Dog rose 2m Downy birch 15m Elder 5m Entandrophragma excelsum 81m Flowering Dogwood 10m Fringe Tree 6m Giant sequoia 96m Goat willow 10m Golden Chain Tree 10m Grand fir 81m Grey willow 10m Guelder rose 5m Hawthorn 15m Hazel 15m Holly 10m Hopea nutans 83m

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 Databases Questions!