Using the Plant base class, do the following now 1. Create a PlantInfo interface that has 2 methods – country of origin (eg Canada) and how used (eg added to soups). Both methods DO NOT receive any...

1 answer below »




Using the Plant base class, do the following now


1. Create a PlantInfo interface that has 2 methods – country of origin (eg Canada) and how used (eg added to soups). Both methods DO NOT receive any parameters, and return a String describing the country of origin or how the plant is used.





2. The Plant class is the top class of the hierarchy. This class is abstract and will implement the PlantInfo interface.
Leave the Plant class as abstract as it will NOT provide the code for these methods.








3. There are three child classes i.e. vegPlant class, MedPlant and a new spicePlant class. (keep the old attributes)



4. The spicePlant child class adds a new data area for part of plant used (seed, fruit, root, bark, etc).




Test the equal method


5. Now, add an

equals

method to the parent class and test that it works by calling it through one of the Vegetable or Spice plant objects.



Show that you can get both true and false values. Also show that this equals method will NOT differentiate between child objects based solely on the child’s variables. Modify the equals method at the end of the document so that it can be used in the Plant class.



6. Modify the equals method at the end of the document so that it can be used in the Plant class.



7. The MedPlant class override the equals method inherited from the parent to include the how sold variable in the test also, and show that it works.


8. Use a cast to access one of the vegPlant objects in the array to call its setPrice and getPrice methods, to show that they work properly. Show that the code works by producing suitable outputs.



9. Use a cast to access one of the medPlant objects in the array to call its setHowSold and getHowSold methods, to show that they work properly. Show that the code works by producing suitable outputs.




10. Make sure to have the usual constructors (default and parameterized), get (accessor) and set (mutator) methods for each attribute, and a toString method.


*** Child classes should call parent methods whenever possible to minimize code duplication,
including the equals method.





Driver program :


1. Use the example done in the class on Wednesday and create the menu driven application to add the different plants, list all the plants added and exit the application. Adding the plant should ask for vegetable, spice or medPlant and take the appropriate parameters and create the object accordingly. Make sure to add country of origin and part of the plant used for each plant.



2. Generate a plantID for each plant –





WE ARE NOT DOING DIFFERENT ID’s. IT IS “P00” FOLLOWED BY NUMBER FOR EACH PLANT.



3. Now add a

new method

– changePlantDetails() to change the plant by looking at the plant id. Once found, check what type of plant it is?


a. If vegPlant – change the price,


b. if medPlant, change the howSold and


c. if spicePlant, change the part of the plant used for.


4. After changing, it should display the country of origin of the plant and also the part of the plant that is useful

Answered Same DayFeb 04, 2022

Answer To: Using the Plant base class, do the following now 1. Create a PlantInfo interface that has 2 methods...

Kshitij answered on Feb 05 2022
105 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here