Question: in java Design and implement these 4 files: A parent/base class called Plant with the following: Attributes - String type/category (eg tree, vegetable, etc) String
in java
Design and implement these 4 files:
- A parent/base class called Plant with the following:
- Attributes - String type/category (eg tree, vegetable, etc)
String name (eg, carrot)
-
- Methods Constructor, getType(), getName(), setType(), setName(), toString()
- Derived class called vegPlant inherits from Plant, with the following:
- Attributes - a price per kilogram
- Methods
- Constructor
- toString
- getPrice(), setPrice()
- Another Derived class medPlant inherits from Plant, with the following:
- Attribute String howSold (eg tincture, bulk powder, capsule, tablet, etc)
- Methods
- Constructor
- toString
- getHowSold(), setHowSold()
- A driver file
To do in driver class:
- Create 1 object of Plant class. 2 objects of vegPlant class (one with no paramaters and one with three permeameter as plant name, plant type and price per kilogram).
- Now create 3 objects of medPlant (one with no parameters, one with only howSold and the third with name, type and howsold)
- Print all the objects
- Now create a new variable in plant as : int defPrice =25;
- In the toString() of medPlant, also show the defPrice value.
Make sure to include comments in your code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
