Last modification: 29/11/16
The Month
enumeration
Create an enumeration which includes every month. We will use it in the below Date
class.
The Date
class
Create a Date
class which represents dates. Use the above Month
type to represent months. Override the equals()
method of Object
.
Create a DateDemo
class which stores some dates in a HashSet
and prints the contents of the set to the output. Create several Date
objects representing the same date, and add them to the set. What happened?
The
polyhedra.Prismabstract class
Create a Prism
class in polyhedra
package which represents prisms.
Store the height of the prism as a double field.
Add a constructor that takes the height of the prism as argument and initializes the field.
Add an abstract area()
method.
Add a final volume()
method that calculates the volume using the height and the surface area.
Make the inherited toString()
method abstract.
Override the inherited equals()
method which decides equality based on volume.
The Cylinder
class
Create a Cylinder
class in polyhedra
package which inherits from the Prism
class.
Implement the abstract area()
and toString
methods.
Prohibit the inheritance from Cylinder
by making it final.
The Cube
class
Create a Cube
class in polyhedra
package which inherits from the Prism
class.
Implement the abstract area()
and toString
methods.
Prohibit the inheritance from Cube
by making it final.
Comparing prisms by volume
Create a class that can compare two prisms by their volumes, that is it implements the java.util.Comparator
interface.
The point of this class is to be able to sort prisms in ascending order according to their volumes using the java.util.Collections.sort()
method.
Comparing prisms by surface areas
Create a class that can compare two prisms by their surface areas, that is it implements the java.util.Comparator
interface.
The point of this class is to be able to sort prisms in ascending order according to their surface areas using the java.util.Collections.sort()
method.