Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

RatiosNoClass BlueJ Project

Click here to download a BlueJ project for RatiosNoClass.


RatiosNoClass Source Code

The Java source code for RatiosNoClass is below. Click on a file name to download it.


RatiosNoClass.java

/*
 * Example RatiosNoClass -- work with a few ratios as motivation for
 * a "Ratio" class
 *
 * Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012
 *
 * $Id: RatiosNoClass.java 2003 2012-12-04 01:42:42Z terescoj $
 */

public class RatiosNoClass {

    public static void main(String[] args) {

        // if we want to represent ratios, we will need a numerator and
        // a denominator for each.
        int aNum = 4;
        int aDen = 6;
        int bNum = 2;
        int bDen = 4;

        // print some information about these
        System.out.println("Ratio a is " + aNum + "/" + aDen);
        System.out.println("Ratio b is " + bNum + "/" + bDen);

        // we can print their decimal equivalents
        double aDecimal = 1.0 * aNum / aDen;
        double bDecimal = 1.0 * bNum / bDen;

        System.out.println("a as a decimal is " + aDecimal);
        System.out.println("b as a decimal is " + bDecimal);
        
        // let's change the ratios a bit, and do the printouts again
        aNum = 1;
        bDen = 10;
        
        System.out.println("Ratio a is " + aNum + "/" + aDen);
        System.out.println("Ratio b is " + bNum + "/" + bDen);

        // we can print their decimal equivalents
        aDecimal = 1.0 * aNum / aDen;
        bDecimal = 1.0 * bNum / bDen;

        System.out.println("a as a decimal is " + aDecimal);
        System.out.println("b as a decimal is " + bDecimal);
        
    }
}