
// Supplies.java
// Andrew Davison, ad@coe.psu.ac.th, May 2023

/* The Cigarette smokers problem:
  https://en.wikipedia.org/wiki/Cigarette_smokers_problem

  A cigarette is made up of three ingredients (supplies): 
  tobacco, paper, and matches. Each ingredient has a value and
  a label.

  Usage:
    > compile.bat Supplies.java

    Part of the application made up of:
       * CigSmokers.java
       * Smoker.java
       * Agent.java
       * Supplies.java
*/


public enum Supplies 
{
  TOBACCO(1, "tobacco"),     // unique value and label
  PAPER(2, "paper"), 
  MATCHES(4, "matches");
    /* I've chosen values so that when any two supplies
       are added together a unique sum is obtained.  
       This sum is calculated inside Agent.run() and tested in 
       Smoker.run(). 
    */
 
  private final int value;
  private final String label;


  private Supplies(int value, String label) 
  {  
    this.value = value;
    this.label = label;
  }


  public int getValue() 
  {  return value; }


  public String toString()
  {  return label;  }


  public static Supplies fromInteger(int val) 
  {
    switch(val) {
    case 1:
        return TOBACCO;
    case 2:
        return PAPER;
    case 4:
        return MATCHES;
    }
    return null;
  } // end of fromInteger()

} // end of Supplies enum

