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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares twoCereals based on their namebooleanTwo be consistent with the natural ordering, twoCereals that have the same name, are themselves the same.getName()Returns the name of this cerealdoublegetPrice()Returns the price of this cerealinthashCode()Two cereals that are equal must have the same hash code.static voidDemonstrates the natural ordering ofCerealsby adding a bunch of cereals to aSortedSettoString()
-
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 twoCereals based on their name- Specified by:
compareToin interfaceComparable<Cereal>
-
equals
Two be consistent with the natural ordering, twoCereals 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 ofCerealsby adding a bunch of cereals to aSortedSet
-