Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Question! Looks long but is supposed to be simple... This is the driver program code: public class PlantCollection { public static void main (String
Java Question! Looks long but is supposed to be simple... This is the driver program code:
public class PlantCollection { public static void main (String [] args) { System.out.println(" Our plant collection has the following: "); System.out.println("A succulent s1 that is a cactus and has red " + "flowers"); System.out.println("A succulent s2 that is not a cactus and has red " + "flowers"); System.out.println("A succulent s3 that is not a cactus and has white " + "flowers"); Plant p1 = new Succulent("red", true); Plant p2 = new Succulent("red", false); Plant p3 = new Succulent(); System.out.println(" The color we have for plant p2 is " + p2.getColor()); System.out.println("It seems that plant s2's color is actually " + "purple, so let's change it"); Succulent s1 = (Succulent) p1; Succulent s2 = (Succulent) p2; Succulent s3 = (Succulent) p3; s2.setColor("purple"); System.out.println(" Plant s1 is a " + s1.getType()); System.out.println("Plant s2 is a " + s2.getType()); System.out.println(" Are succulents s1 and s2 the same type? " + (s1.isSameType(s2) ? "Yes" : "No")); System.out.println(" Let's add two ferns to our collection:"); Plant s4 = new Fern(); Plant s5 = new Fern(); System.out.println(s4); System.out.println(s5); Fern f1 = (Fern) s4; Fern f2 = (Fern) s5; System.out.println("Comparing watering of ferns:"); System.out.println("f1 " + f1.getWatering() + " days"); System.out.println("f2 " + f2.getWatering() + " days"); int result = f1.compareTo(f2); System.out.println("Fern one needs to be watered " + ((result == 0) ? "the same as" : (result == 1) ? "less often than" : "more often than") + " fern 2"); System.out.println(" There are " + Plant.numberOfPlants() + " plants in our collection"); Plant [] collection = {s1, s2, s3, s4, s5}; System.out.println(" Here's what our collection looks like: "); for (int i = 0; i 1) Create an abstract class Plant with the following features: class variable ENERGY_SOURCE with value "carbon dioxide class variable called plants to count plant objects class method numberofPlants() that returns number of plant objects instance variable for color no-argument constructor that sets flower color to none constructor that takes a user-specified color getter setter toString) abstract method getWatering() that returns integer for number of days after which plant needs to be watered 2) Create a Fern class that extends Plant and implements the comparable interface no argument constructor that assigns default value of none for color (since ferns don't have flowers) method getWatering0 that returns 7 four out of five times and 14 the fifth time (since ferns need weekly watering unless it is very humid; use Math.random0) 3) Create a Succulent class that extends Plant that contains the following: instance variable hasSpines that is set to true if plant is a cactus, false otherwise no-argument constructor that assigns default value of false for hasSpines and purple for color constructor that assigns user-specified values for hasSpines and color getter (call it hasSpines rather than getSpines since it returns a boolean) setter toString) method getType) that returns "cactus" if hasSpines is true, "succulent" otherwise method isSameType0 that returns true if both plants are the same subtype method getWatering) that returns 28 for cacti, 14 otherwise
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started