/****
 * Fraction class from 3.8 in the text
 *
 ******/

public class Fraction {

    private int numerator;
    private int denominator;

    public Fraction( int num, int denom ){
	numerator   = num;
	denominator = denom;
    }

    public Fraction(){
	numerator = 0;
	denominator = 1;
    }
    
    public Fraction(int num){
	numerator = num;
	denominator = 1;
    }

    public int getNumerator(){
	return numerator;
    }

    public int getDenominator(){
	return denominator;
    }

    public void setNumerator(int num){
	numerator = num;
    }

    public void setDenominator(int denom){
	denominator = denom;
    }

    public Fraction add(Fraction f){
	int num = numerator*f.getDenominator() + f.getNumerator()*denominator;
	int denom = denominator * f.getDenominator();
	Fraction result = new Fraction(num,denom);
	return result;
    }
    
    public void printIt(){
	System.out.println( " " + numerator + "/" + denominator );
    }

}


syntax highlighted by Code2HTML, v. 0.9.1