From N V Fitton, ideas to share with my students at Northern Virginia Community College, Alexandria campus.
I teach mathematics and computer science.

Monday, March 21, 2005

201 notes on Point and Triangle objects




// a part of class Point ///////////////////////////

// two equivalent ways of computing distance

// syntax for Point objects p1, p2
// Point.distance(p1, p2);

public static double distance(Point p, Point q) {

double dx = p.x - q.x;
double dy = p.y - q.y;

dx *= dx;
dy *= dy;

return Math.sqrt(dx + dy);
}

// syntax for Point objects p1, p2
// p1.distance(p2);

public double distance(Point q) {

double dx = this.x - q.x;
double dy = this.y - q.y;

dx *= dx;
dy *= dy;

return Math.sqrt(dx + dy);
}


// a part of class Triangle ////////////////////////

// with a constructor rather than set() methods

// syntax for Point objects v1, v2, v3 (vertices)
// Triangle t = new Triangle(v1, v2, v3);

public class Triangle {

private Point a, b, c;

public Triangle(Point aa, Point bb, Point cc) {
a = aa;
b = bb;
c = cc;
}



public double perimeter() {
return 0.0;

// nominal value here
// to be replaced after interface is written
}

public double area() {
return 0.0;

// nominal value here
// to be replaced after interface is written
}
}


0 Comments:

Post a Comment

<< Home