/** Ph.java models pH values.
 *  @author Joel Adams
 */

public class PH {
	public static final double MIN = 0.0;
	public static final double MAX = 14.0;
	public static final double NEUTRAL = 7.0;

	/** Construct a PH object.
	 * @param pH, a double.
	 * Precondition: pH is a valid pH value (in the range 0..14).
	 * Postcondition: myPH == pH.
	 */
	public PH(double pH) {
        if (pH < MIN || pH > MAX) {
        	throw new IllegalArgumentException("*** PH(pH): pH = " + pH + "\n");
        } else {
        	myValue = pH;
        }
	}

	/** Return the correct label for a given pH value.
	 *  @param pH, a double.
	 *  @return "acidic", "alkaline", "neutral", or "error".
	 */

	public String label() {
		if (myValue < MIN || myValue > MAX) { // check pH's validity first
			return "error";
		} else if (myValue < NEUTRAL) { // then check acidity
			return "acidic";
		} else if (myValue > NEUTRAL) { // then alkalinity
			return "alkaline";
		} else { // if it's none of the above
			return "neutral"; //  it must be neutral
		}
	}
	
	private double myValue;
}
