CS46A Spring 18

11A

In this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no parameters and returns a double.

To create an interface in Bluej, click the New Class button and choose interface rather than class. Give it a name and click OK.

You are provided with three classes: CylinderSphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume (updated Apr 28)

Use Math.PI.

Notice in InterfaceRunner in the final version that the objects are added to an ArrayList of GeometricSolids.

For the draft: write the GeometricSolid interface and then modify Sphere class to implement the GeometricSolid interface. You will need to upload both the interface and the Sphere class to Codecheck

11A draft:
11A final:

 

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

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

Trees are ordered first by height with the smallest coming first. If two Trees have the same height, the Trees are ordered alphabetically by type in lexicographical order. If this Tree should come before the other tree ,compareTo returns a negative integer. If this Tree should come after the other Tree, 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 Tree (That means you will have to cast in the final)

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

public int compareTo(Object otherObject)

Note: You will get a compiler warning about "unsafe or unchecked operations" when you compile TreeRunner. 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 own. TVs 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.

TV has methods getSize() and  getBrand()

A toString method is provided for you. This is to help 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: