The RationalDemo Class

/*
Author: Ben McCrea
Class: RationalDemo
Purpose: to create 2 objects from the Rational class
         and display their values on the screen
Date: 2/27/02
*/

import java.awt.*;
import java.applet.Applet;

public class RationalDemo extends Applet{

      //declaring two Rational variables
      public Rational fraction1;
      public Rational fraction2;

      public void init(){

         //using a constructor to initialize
         //a Rational object
         fraction1 = new Rational();

         //using the second constructor to initialize
         //a Rational object
         fraction2 = new Rational(4, 5);
      }

      public void paint(Graphics g){
         g.drawString("The numerator of fraction1 is: " + 
                       fraction1.numerator, 10, 10);
         g.drawString("The denominator of fraction1 is: " +
                       fraction1.denominator, 10, 30);

         g.drawString("The numerator of fraction2 is: " + 
                       fraction2.numerator, 10, 50);
         g.drawString("The denominator of fraction2 is: " +
                       fraction2.denominator, 10, 70);

         g.drawString("The decimal equivalent of fraction2 is: " +
                       fraction2.makeDouble(), 10, 90);
   
      }
}
View the Rational class
Back to the home page