import java.util.*;
public class Point {
//ATTRIBUTES
double x;
double y;
public Point(){
x = 0;
y = 0;
}
public Point(double a, double b){
x = a;
y = b;
}
public double getX(){
return x;
}
public double getY(){
return y;
}
public void move(double a,double b){
x = a;
y = b;
}
public double distanceTo(Point p){
double distance =
Math.pow(x - p.getX(),2) +
Math.pow(y - p.getY(),2);
return Math.sqrt(distance);
}
public double distanceTo(double a,double b){
double distance =
Math.pow(x - a,2) +
Math.pow(y - b,2);
return Math.sqrt(distance);
}
}
public class LineSegment {
//ATTRIBUTES
Point endpoint1;
Point endpoint2;
public LineSegment(Point a, Point b){
endpoint1 = a;
endpoint2 = b;
}
public double length(){
return endpoint2.distanceTo(endpoint1);
}
public Point midpoint(){
double x =
(endpoint1.getX() + endpoint2.getX())/2;
double y =
(endpoint1.getY() + endpoint2.getY())/2;
Point midpoint = new Point(x,y);
return midpoint;
}
public double slope(){
double rise =
endpoint1.getY() - endpoint2.getY();
double run =
endpoint1.getX() - endpoint2.getX();
return rise/run;
}
public String getLine(){
String s =
"Y = ";
s = s + slope() + "(X) - ";
s =s + (slope()*endpoint1.getX() + endpoint1.getY());
return s;
}
}
CS Point and Line Segments Program
Labels:
compsci
In-email ni Sir Paolo, kasi hindi in-email ni Domz. :>
Post a Comment
Hi. :-h