/*    Program to demonstrate basic Java data types    Version 1.0    Written by: STF    (c) University of Otago, Dept. of Computer Science, 2001.        Updated by James Little for Exercise 2 cosc241 8/3/01.    And again for exercise 2 15/3/01.*/package jlittle_ex2;import basicIO.*;import java.text.*;import java.io.*;/** * This is a Basic Data class... to increase my knowledge of basic (java) data type */public class BasicData {    public static void runTypeTests() {        // integers        byte largestByte = Byte.MAX_VALUE;        byte smallestByte = Byte.MIN_VALUE;        short largestShort = Short.MAX_VALUE;	short smallestShort = Short.MIN_VALUE;        int largestInteger = Integer.MAX_VALUE;        int smallestInteger = Integer.MIN_VALUE;        long largestLong = Long.MAX_VALUE;        long smallestLong = Long.MIN_VALUE;        // real numbers        float largestFloat = Float.MAX_VALUE;        float smallestFloat = Float.MIN_VALUE;        double largestDouble = Double.MAX_VALUE;        double smallestDouble = Double.MIN_VALUE;        // display them all        Out.println("Range of byte is from "                    + smallestByte + " to " + largestByte);        Out.println("Range of short is from "                    + smallestShort + " to " + largestShort);        Out.println("Range of int is from "                    + smallestInteger + " to " + largestInteger);        Out.println("Range of long is from "                    + smallestLong + " to " + largestLong);	Out.println("Range of float is from "            	    + smallestFloat + " to " + largestFloat);	Out.println("Range of double is from "            	    + smallestDouble + " to " + largestDouble);    } // end runTypeTests method    /**     * Run some tests using approximations to PI     */    public static void runPITests() {        double circleRadius = 10.0;         double circumference = 2*Math.PI*circleRadius;        DecimalFormat df = new DecimalFormat("0.#");        Out.println("Circumference of a circle with 10m radius is: "         			+ df.format((circumference)) + " m.");    } // end runPITests method    /**     * Run some tests with squares of numbers     */    public static void runSquareTests() {        int x;		// can't convert int to short, so I made x int.        short y;		// y can be short because its range is only <200	short start = 150;	int end = 200;        for (y=start; y<end; y++) {            x = y * y;	        // where x must go to 39601.. it cannot be short            Out.println("The square of " + y + " is " + x);        } // end for loop    } // end runSquareTests method    /**     * Run some tests finding intersections between lines.     * Refer to Line.java and Line.class documentation for details.     */    public static void runLineTests() {        Line line1;        Line line2;        Line line3;        Line line4;        Point intersectPt;        // line 1 is y=-x+4        line1 = new Line(1, 1, -4);        // line 2 is y=x+2        line2 = new Line(-1, 1, -2);        // line 3 is x=3        line3 = new Line(-1, 0, 3);        // line 4 is y=-x+1        line4 = new Line(1, 1, -1);				intersectPt = new Point();        // lines 1 and 2 should intersect        if (line1.intersects(line2, intersectPt))            Out.println("CORRECT: Intersection found at ("                        + intersectPt.getX() + ", "                        + intersectPt.getY() + ")");        else            Out.println("ERROR: No intersection found for lines 1 and 2");        // lines 1 and 4 should not intersect (they are parallel)        if (line1.intersects(line4, intersectPt))            Out.println("ERROR: Intersection found for lines 1 and 4");        else            Out.println("CORRECT: No intersection found for lines 1 and 4");        // vertical line 3 should intersect with line 2        if (line3.intersects(line2, intersectPt))            Out.println("CORRECT: Intersection found at ("                        + intersectPt.getX() + ", "                        + intersectPt.getY() + ")");        else            Out.println("ERROR: No intersection found for lines 3 and 2");        // line 2 should intersect with line 4        if (line2.intersects(line4, intersectPt))            Out.println("CORRECT: Intersection found at ("                        + intersectPt.getX() + ", "                        + intersectPt.getY() + ")");        else            Out.println("ERROR: No intersection found for lines 2 and 4");    } // end runLineTests method    /**     * Run some tests to illustrate Java data types and calculations     */    public static void main(String[] args) {        runTypeTests();        runPITests();        runSquareTests();        runLineTests();        Out.println("END OF OUTPUT");    } // end main method} // end BasicData class
-----------------------------131333792316667876911358593345
Content-Disposition: form-data; name="userfile"; filename="Line.java"

/*    Line.java    Stewart Fleming    March 2001    Implements requirements for measurement system 11.2 Line        Updated by James Little for cosc 241 exercise 2 8/3/01.    And again for exercise 2 15/3/01.      */package jlittle_ex2;/** * Represents a line with the equation Ax + By + C = 0 */public class Line {   /**       a, b and c represent the line in parametric form.       Ax + By + c = 0       This is a more efficient representation for calculations.       The gradient specified in requirement 11.2.1 is: m = -A/B    */    private double a, b, c;    /** the start and end points of the line */    Point startPt, endPt;    /** Construct an empty line */    Line(){     	a = b = c = 0.0;    } // end of Line    /** Construct a line with specific coefficients */    Line(int xCoeff, int yCoeff, int cOffset) {        a = xCoeff;        b = yCoeff;        c = cOffset;    } // end of constructor    /**     * Construct a line between two points.     * Requirement 11.2.2     */    Line(Point pt1, Point pt2)    {        // calculate the coefficients for the line between the points        a = (double) (pt2.getY() - pt1.getY());        b = (double) (pt1.getX() - pt2.getX());        c = (-a * (double) pt1.getX()) - (b * (double) pt1.getY());        // set the start and end points of the line        startPt = pt1;        endPt = pt2;    } // end of constructor    /**     * Indicate if a point lies on the line.     * Requirement 11.2.7     */    public boolean containsPoint(Point pt) {        return ((a * (double) pt.getX()) + (b * (double) pt.getY()) + c == 0.0);    } // end containsPoint method    /**     * Indicate if this line intersects with the line specified.     * This line: Ax+ By + C = 0     * Line1: A'x + B'y + c' = 0     * The lines do not intersect if AB' - A'B = 0.     * Otherwise the intersection point is:     * y = (A'C - AC') / (AB' - A'B)     * x = (BC' - B'C) / (AB' - A'B)     * Requirement 11.2.8     */    public boolean intersects(Line line1, Point intersectPt) {        double denom, x, y;                // nobody appeared to be using denom so I thought I would use it.        denom = ((a * line1.b) - (line1.a * b));	// if AB' - A'B = 0, then there is no intercept, and I want to return false        if(denom!=0.0){	    x = ((b * line1.c) - (line1.b * c)) / ((a * line1.b) - (line1.a * b));	    y = ((line1.a * c) - (a * line1.c)) / ((a * line1.b) - (line1.a * b)); 	    intersectPt.setX((int) x);	    intersectPt.setY((int) y);	    return true;	} else 	    return false;    }// end intersects method    /** Indicates if the line is EXACTLY horizontal */    public boolean isHorizontal() {        return (a == 0.0);    } // end isHorizontal method    /** Indicates if the line is EXACTLY vertical */    public boolean isVertical() {        return (b == 0.0);    } // end isVertical method} // end of class Line