Question: in java Problem Design and implement these 4 files: A parent/base class called Plant with the following: Attributes - String type/category (eg tree, vegetable, etc)

in java

Problem

Design and implement these 4 files:

  1. A parent/base class called Plant with the following:
    1. Attributes - String type/category (eg tree, vegetable, etc)

String name (eg, carrot)

    1. Methods Constructor, getType(), getName(), setType(), setName(), toString()
  1. Derived class called vegPlant inherits from Plant, with the following:
    1. Attributes - a price per kilogram
    2. Methods
      1. Constructor
      2. toString
      3. getPrice(), setPrice()

  1. Another Derived class medPlant inherits from Plant, with the following:
    1. Attribute String howSold (eg tincture, bulk powder, capsule, tablet, etc)
    2. Methods
      1. Constructor
      2. toString
      3. getHowSold(), setHowSold()

  1. A driver file

To do in driver class:

  1. 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).
  2. Now create 3 objects of medPlant (one with no parameters, one with only howSold and the third with name, type and howsold)
  3. Print all the objects
  4. Now create a new variable in plant as : int defPrice =25;
  5. 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

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!