Question: Java code PLEASE FAST!! The saying goes that one should not compare apples to pears. I disagree somewhat. Start a new source folder or project.

 Java code PLEASE FAST!! The saying goes that one should not

Java code PLEASE FAST!!

The saying goes that one should not compare apples to pears. I disagree somewhat. Start a new source folder or project. Create a class Apple, having attributes weight, colour, ripe and spoiled. Finish this class. Create a class Pear, having attributes weight, color and spoiled (they will never be ripe I guess.) Finish this class. Create a test class having a TreeSet of apples. Add a bunch of apples with random weights. Loop over the set and print the apples. As you can see, this is not working. Have Apple implement the interface Comparable, using weight as the distinguishing factor. Print the set again. Do the same with a set of Pears. 15.5 Some are more equal than others Can you create a List containing both Apples and Pears? Please do so by creating a class Fruit and adapting Apple and Pear to extend Fruit. 15.6 Fruit for control freaks A TreeSet is a class which works quite a bit like an ArrayList, but which only accepts unique objects and sorts them according to their compareTo(Object o) method. That means that in order to use a TreeSet you need to use objects which implement the Comparable interface. Can you create a TreeSet containing both apples and pears? Copy the code from 15.5 to a new folder. Change the code in such a way that you can have a TreeSet containing both apples and pears

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!