CS46A Fall 19

11A

In this problem you will be using the Data class from your textbook. Remember that the Data class contains methods to find the average or the largest value in any array of objects which implement the Measurable interface.

You are given a class, Tree. You will implement the Measurable interface in the Tree class. A Tree is measured by its height. Then complete the TreeRunner class to find the average height of the trees and the type of the tallest tree.

For the draft, implement the Measurable interface in the Tree class.

Although the Tree class will not change, you will need to paste it into the textarea for the final.

Remember that the return value of largest is a reference to a Measurable object. Using that reference, you can not get the type of the object because Measurable has no getType method. (Think cast)

11A draft:
11A final:

11B

Modify the Plant class from hw10C to implement the Comparable interface from the Java library. Do not write your own Comparable interface. 

If you need a working version of the Plant class, you can get it from the solutions.

Plant are ordered first by price with the smallest coming first. If two Plant have the same price, the Plant are ordered alphabetically by name in lexicographical order. If this Plant should come before the other Plant, compareTo returns a negative integer. If this Plant should come after the other Plant, it returns a positive integer. Otherwise, it returns 0.

For the final version, remember about using Double.compare to compare doubles.

Note: The compareTo method takes an Object as parameter not a Plant (That means you will have to cast in the final)

For the draft, add the "implements Comparable" clause to the Plant class header and implement compareTo as a stub. The header is:

public int compareTo(Object otherObject)

Note: You may get a compiler warning about "unsafe or unchecked operations" when you compile PlantRunner. You can safely ignore it for now.

11B draft:
11B final:

11C

Write a class to model a television set. A TV has a constructor that takes the brand as a String. It also takes double , size, which is the screen size. Call the instance variables brand and size. The size is measured on the diagonal.

TV  implements the the Comparable  interface from the Java library. Do not write your ownTVs are ordered by size. If two TVs have the same size, then the TV with the brand that comes first in the lexicographical (alphabetical) order is the smaller. For Example, "LG" comes before "Sharp" alphabetically and so is the smaller if both have the same screen size.

TV has methods getSize() and  getBrand()

toString method is provided for you. Do not remove it. It is to help me in testing your code.

Provide Javadoc.

Remember that the compareTo method take a Object as parameter not a TV (That means you will have to cast)

For the draft, supply the instance variables, the constructor and the getSize()and getBrand() methods.

11C draft:
11C final: