Package edu.pdx.cs410J.core
Class Cereal
java.lang.Object
edu.pdx.cs410J.core.Cereal
- All Implemented Interfaces:
Comparable<Cereal>
This class represents a box of cereal. It has a name and a price.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Compares twoCereal
s based on their nameboolean
Two be consistent with the natural ordering, twoCereal
s that have the same name, are themselves the same.getName()
Returns the name of this cerealdouble
getPrice()
Returns the price of this cerealint
hashCode()
Two cereals that are equal must have the same hash code.static void
Demonstrates the natural ordering ofCereals
by adding a bunch of cereals to aSortedSet
toString()
-
Constructor Details
-
Cereal
Creates a new box of cereal
-
-
Method Details
-
getName
Returns the name of this cereal -
getPrice
Returns the price of this cereal -
toString
-
compareTo
Compares twoCereal
s based on their name- Specified by:
compareTo
in interfaceComparable<Cereal>
-
equals
Two be consistent with the natural ordering, twoCereal
s that have the same name, are themselves the same. -
hashCode
Two cereals that are equal must have the same hash code. -
main
Demonstrates the natural ordering ofCereals
by adding a bunch of cereals to aSortedSet
-