// Should place bean in package
package com.ACME;


// This bean represents a fraction in the form numerator/denominator.
// Users can set and get the numerator and denominator, and get the
// corresponding decimal value.
 
public class FractionBean {

  private int numerator;
  private int denominator;

  // Note that we must provide a construtor with no parameters. This
  // is called when the bean is loaded.

  public FractionBean() {
    numerator = 0;
    denominator = 1;
    }

  // Methods should be in the form getProperty and 
  // setProperty (parameter), where "property" is an
  // identifier used by the JSP page. 

  // Note that while at an abstract level these methods 
  // just get/set properties, we can have them do sophisticated
  // validation, evaluation, etc.

  public void setNumerator(String n) {
    try {numerator = Integer.parseInt(n);}
    catch (NumberFormatException ex) {}
    }

  public void setDenominator(String n) {
    try {denominator = Integer.parseInt(n);}
    catch (NumberFormatException ex) {}
    }

  public String getNumerator() {
    return "" + numerator;
    }

  public String getDenominator() {
    return "" + denominator;
    }

  public String getValue() {
    if (denominator == 0) 
      if (numerator == 0) return "undefined";
      else return "infinity";
    else return "" + ((double)numerator/denominator);
    }

  }

