Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create your parent class in IntelliJ. This will be an abstract class. It must include: Two or more private data members Two constructors - No-arg

  1. Create your parent class in IntelliJ. This will be an abstract class. It must include:

    1. Two or more private data members

    2. Two constructors - No-arg and all-arg constructors set as protected

    3. Setters and Getters for each data member

    4. A toString() method with a modified return (modified means do not use the default String)

    5. A relevant abstract void method that will eventually be defined in your two child classes.

  2. You will also implement the Comparable interface in this class and set up the compareTo() method. You can choose which of your data members you use in the method.

  • Part 3: Child Classes

  1. Create your two child classes. These will not be abstract. Each child class must:

    1. Extend the parent class

    2. Define two more additional unique private data members each

    3. Contain two constructors - no-arg and all-arg constructors for each (the all-arg must utilize super so that the parent class values get set as well)

    4. Include setters and Getters for each new data member

    5. A toString() method for each that includes super.toString() along with the unique information for each child class

    6. The implementation of the abstract method that you created in the parent class. For simplicitys sake, just have it print something specific to each child type.

  2. You will not implement Comparable in either of your child classes. This isnt necessary since I just want a sorting mechanism that can be applied to any and all child types.

  • Part 4: MainApp

  1. Create a main application and inside create an ArrayList that stores your parent type.

  2. Add three objects from each child type for a total of six objects in the ArrayList.

  3. Use a for each loop to loop through the ArrayList. For each object in the ArrayList print the toString() and call the extra method (the one that overrode the abstract method in the parent class.)

  4. Use Collections.sort() to sort your ArrayList. (This does not go in a loop.)

  5. Use a for loop to loop through the ArrayList again, printing the same items in step 3. Make sure your sorting worked as defined in your compareTo() method.

  6. Note the different looping requests above. Make sure the first one is a for each loop and the second one is a for loop.

My Example:

Parent Class: Plant

  • Data Members: name, maxHeight

  • Abstract Method: getUpkeepInformation()

  • Comparable compareTo() Method: Will sort alphabetically by name.

Child Class 1: Flower

  • Data Members: color, cutFlower? (boolean indicating if its a flower meant for cutting/bouquets/florists)

  • The Overridden getUpkeepInformation() Method: Will print a statement indicating if a plant requires full sun or not. (This is just a hard-coded print statement. If we wanted to fully flesh this class out, this would make more sense. For the purpose of the lab, just come up with something semi-relevant.)

Child Class 2: Shrub

  • Data Members: type, dateForPruning

  • The Overridden getUpkeepInformation() Method: Will print a statement indicating how often pruning should occur.

MainApp: I will create an ArrayList of Plant objects and then create three Flower objects (with all four pieces of information passed in) and three Shrub objects (also with all four pieces of information passed in). I will print the ArrayList as requested, then sort, then print again. Shown below is the toString() followed by my extra void method print statement for each object. My final output might look something like this.

Final Output:

Dwarf Sunflower has a max height of 12.0 inches. It is Yellow/Black and is a cut flower.

A Dwarf Sunflower requires full sun.

Nasturtium has a max height of 12.0 inches. It is Orange/Red/Yellow and is not a cut flower.

A Nasturtium requires full sun.

State Fair Zinnia has a max height of 16.0 inches. It is Multi-colored and is a cut flower.

A State Fair Zinnia requires full sun.

A Boxwood is a(n) evergreen shrub with a maximum height of 30 feet. It should be pruned in the spring.

Pruning should occur once a year.

A Japanese Spirea is a(n) deciduous shrub with a maximum height of 4 feet. It should be pruned in the late winter.

Pruning should occur once a year.

A Flaky Juniper is a(n) evergreen shrub with a maximum height of 3 feet. It should be pruned in the early spring.

Pruning should occur once a year.

*************Sort using Collections.sort()********************

Boxwood is a(n) evergreen shrub with a maximum height of 30 feet. It should be pruned in the spring.

Pruning should occur once a year.

Dwarf Sunflower has a max height of 12.0 inches. It is Yellow/Black and is a cut flower.

A Dwarf Sunflower requires full sun.

Flaky Juniper is a(n) evergreen shrub with a maximum height of 3 feet. It should be pruned in the early spring.

Pruning should occur once a year.

Japanese Spirea is a(n) deciduous shrub with a maximum height of 4 feet. It should be pruned in the late winter.

Pruning should occur once a year.

Nasturtium has a max height of 12.0 inches. It is Orange/Red/Yellow and is not a cut flower.

A Nasturtium requires full sun.

State Fair Zinnia has a max height of 16.0 inches. It is Multi-colored and is a cut flower.

A State Fair Zinnia requires full sun.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

=+1. Give the balance sheet to Melissa.

Answered: 1 week ago