edu.pdx.cs399J.core
Class Cereal

java.lang.Object
  extended by edu.pdx.cs399J.core.Cereal
All Implemented Interfaces:
Comparable<Cereal>

public class Cereal
extends Object
implements Comparable<Cereal>

This class represents a box of cereal. It has a name and a price.


Constructor Summary
Cereal(String name, double price)
          Creates a new box of cereal
 
Method Summary
 int compareTo(Cereal c2)
          Compares two Cereals based on their name
 boolean equals(Object o)
          Two be consistent with the natural ordering, two Cereals that have the same name, are themselves the same.
 String getName()
          Returns the name of this cereal
 double getPrice()
          Returns the price of this cereal
 int hashCode()
          Two cereals that are equal must have the same hash code.
static void main(String[] args)
          Demonstrates the natural ordering of Cereals by adding a bunch of cereals to a SortedSet
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Cereal

public Cereal(String name,
              double price)
Creates a new box of cereal

Method Detail

getName

public String getName()
Returns the name of this cereal


getPrice

public double getPrice()
Returns the price of this cereal


toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(Cereal c2)
Compares two Cereals based on their name

Specified by:
compareTo in interface Comparable<Cereal>

equals

public boolean equals(Object o)
Two be consistent with the natural ordering, two Cereals that have the same name, are themselves the same.

Overrides:
equals in class Object

hashCode

public int hashCode()
Two cereals that are equal must have the same hash code.

Overrides:
hashCode in class Object

main

public static void main(String[] args)
Demonstrates the natural ordering of Cereals by adding a bunch of cereals to a SortedSet



Copyright © 2000-2009 Portland State University. All Rights Reserved.