Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Line {
- private Point A;
- private Point B;
- public Line() {
- A=new Point(0, 0);
- B=new Point(0, 1);
- }
- public Line(Point A, Point B) {
- this.A = A;
- this.B = B;
- }
- public Line(double x1,double x2, double y1, double y2){
- this.A=new Point(x1,y1);
- this.B=new Point(x2,y2);
- }
- public double getLength(){
- double dx=Math.abs(A.getX()-B.getX());
- double dy=Math.abs(A.getY()-B.getY());
- return Math.sqrt(dx*dx+dy*dy);
- }
- public double getDiagonal(){
- return Math.sqrt(2)*getLength();
- }
- public double getPerimeter(){
- return 4*getLength();
- }
- public double getSquare(){
- return Math.pow(getLength(),2);
- }
- public Point getA() {
- return A;
- }
- public Point getB() {
- return B;
- }
- public void setA(Point A) {
- this.A = A;
- }
- public void setB(Point B) {
- this.B = B;
- }
- @Override
- public String toString(){
- return "Line(point A("+A.getX()+","+A.getY()+"); point B("+B.getX()+","+B.getY()+")";
- }
- }
Add Comment
Please, Sign In to add comment