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
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
examples for list of plants and trees that need to be called in code by putting them in the same directory as the code:
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
Get step-by-step solutions from verified subject matter experts
