Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Plant Class: Contains private data for name and price. Use a NON-default constructor to assign the values. Use a toString() method that will display as shown in the sample output. Include any...

1 answer below »

Plant Class:

Contains private data for name and price.

Use a NON-default constructor to assign the values.

Use a toString() method that will display as shown in the sample output.

Include any accessor/mutator if needed, in this class only!

Indoor Class:

Inherits from the Plant class.

Contains private data for sunlight (direct, partial, none etc.) and number of days it should be watered.

Your constructor will NOT assign the data for sunlight and number of days.

Use a setData() method that will ask the user for sunlight and number of days.

Use a toString() method that will display as shown in the sample output.

Outdoor Class:

Inherits from the Plant class.

Contains private data for a minimum and maximum hardiness zone (1-9).

Your constructor will NOT assign the data for hardiness zones.

Use a setData() method that will ask the user for hardiness zones.

Use a toString() method that will display as shown in the sample output.

Tree Class:

Inherits from the Outdoor class.

Contains private data for a minimum and maximum height in feet.

Your constructor will NOT assign the data for height.

Use a setData() method that will ask the user for height.

Use a toString() method that will display as shown in the sample output.

Garden Class:

Inherits from the Outdoor class.

Contains private data for a minimum and maximum height in inches.

Your constructor will NOT assign the data for minimum and maximum height in inches.

Use a setData() method that will ask the user for minimum and maximum height in inches.

Use a toString() method that will display as shown in the sample output.

Plant Program:

Your main() will contain an ArrayList capable of holding indoor plants, trees, and garden plants. You will send the ArrayList to a loadInventory() method that will continually ask the user what type of plant they wish to add, followed by the name and price. Your program will then use this information to create the appropriate object and add it to the ArrayList. NO data validation is required (assume people are perfect!).

Your main() will then call a loadPlantData() method that will accept the ArrayList and use a for-each loop to display the plant name and call the setData() method for that object.

Lastly, the main() method will use a for-each loop and print all the data in the Arraylist using the toString() methods.

Sample Output:

Select the type of plant:

1) Indoor

2) Tree

3) Garden

1

Enter the name of the plant: Fern

Enter the price of the plant: 14.99

Do you have another plant to add? yes

Select the type of plant:

1) Indoor

2) Tree

3) Garden

2

Enter the name of the plant: Pine

Enter the price of the plant: 175.50

Do you have another plant to add? yes

Select the type of plant:

1) Indoor

2) Tree

3) Garden

3

Enter the name of the plant: Lily

Enter the price of the plant: 3.99

Do you have another plant to add? No

Enter data for Fern

Enter the type of sunlight: Partial

Enter the number of days per week to be watered: 2

Enter data for Pine

Enter the min hardiness zone: 2

Enter the max hardiness zone: 8

Enter the minimum height in feet: 20

Enter the maximum height in feet: 60

Enter data for Lily

Enter the min hardiness zone: 4

Enter the max hardiness zone: 7

Enter the minimum height in inches: 6

Enter the maximum height in inches: 12

Current Inventory

Fern $ 14.99 Partial sunlight and water 2 day(s) per week

Pine $ XXXXXXXXXXZones: 2 - 8 Max Height: 60 Max Age: 20

Lily $ 3.99 Zones: 4 - 7 Max Height: 12 Min Height: 6

Answered 1 days After Oct 26, 2021

Solution

Aditya answered on Oct 28 2021
121 Votes
New folde
Garden.java
New folde
Garden.java
import java.util.Scanner;
public class Garden extends Outdoor{
    
    private int minHeight;
    private int maxHeight;
    public Garden(String name, double price) {
        super(name, price);
    }
    public void setData() 
    {
        super.setData();
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the minimum height in inches: ");
        minHeight = scanner.nextInt();
        System.out.print("Enter the maximum height in inches: ");
        maxHeight = scanner.nextInt();
        
    }
    @Ove
ide
    public String toString() {
        return super.toString()+" Max Height: " + maxHeight + " Min Height " + minHeight ;
    }
}
New folde
Indoor.java
New folde
Indoor.java
import java.util.Scanner;
public class Indoor extends Plant{
    private String sunlight;
    private int numOfDays;
    
    public Indoor(String name, double price) {
        super(name, price);
    }
    
    public void setData() 
    {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the type of sunlight: ");
        sunlight = scanner.nextLine();
        System.out.print("Enter the number of days per week to be watered: ");
        numOfDays = scanner.nextInt();
        
    }
    @Ove
ide
    public String toString() {
        return super.toString()+" " + sunlight + " and water " + numOfDays + " day(s) per week";
    }
    
    
    
}
New folde
Outdoor.java
New...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here