Class Cereal

java.lang.Object
edu.pdx.cs410J.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

    Constructors
    Constructor
    Description
    Cereal(String name, double price)
    Creates a new box of cereal
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares two Cereals based on their name
    boolean
    Two be consistent with the natural ordering, two Cereals that have the same name, are themselves the same.
    Returns the name of this cereal
    double
    Returns the price of this cereal
    int
    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
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Cereal

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

    • 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