0

I am trying to get the values of a start point and end point of a line. When i print the output shows the address. Apologies in advance for the format but this is my first question so any feedback would be appreciated. here is my LineSegment class:

package geometry;

public class LineSegment {
    private CartesianCoordinate startPoint;
    private CartesianCoordinate endPoint;
    
    public LineSegment(double x1,double x2, double y1, double y2) {
        startPoint = new CartesianCoordinate(x1,y1);
        endPoint = new CartesianCoordinate(x2,y2);
    }
    
    
    public LineSegment(CartesianCoordinate startPoint,CartesianCoordinate endPoint) {
        
        this.startPoint = startPoint;
        this.endPoint = endPoint;
        
    }
    public CartesianCoordinate getStartPoint() {
        return startPoint;
    }
    
    public CartesianCoordinate getEndPoint() {
        return endPoint;
    }
    public String toString() {
        return "Line between: (" + startPoint +  endPoint + ")";
    }
}

here is my CartesianCoordinate class:

package geometry;

public class CartesianCoordinate {
    private double xPosition;
    private double yPosition;
    
    public CartesianCoordinate(double x, double y) {
        xPosition = x;
        yPosition = y;
    }

    public double getX(){
        return xPosition;
    }
    
    public double getY() {
        return yPosition;
    }
    
    
    
}

here is my main:

import geometry.CartesianCoordinate;
import geometry.LineSegment;

public class Lab3Test {
        public static void main (String[]args) {
            System.out.println("Lab 3 Test");
            Lab3Test lab3Test = new Lab3Test();
            lab3Test.testCoordinate();
            lab3Test.testLineSegment();
        }
        private void testCoordinate() {
            CartesianCoordinate a;
            CartesianCoordinate b;
            a = new CartesianCoordinate(1.4,2.2); 
            b = new CartesianCoordinate(4.4,6.2);
            System.out.println("X(a)="+a.getX()+" Y(a)="+a.getY());
            System.out.println("X(b)="+b.getX()+" Y(b)="+b.getY());
        }
        private void testLineSegment() {
            LineSegment line;
            CartesianCoordinate a;
            CartesianCoordinate b;
            a = new CartesianCoordinate(1.4,2.2);
            b = new CartesianCoordinate(4.4, 6.2);
            line = new LineSegment(a,b);
            System.out.println(line);
            
        }
}

This is the output i get:

Lab 3 Test
X(a)=1.4 Y(a)=2.2
X(b)=4.4 Y(b)=6.2
X(a)=1.4 Y(a)=2.2
Line between: (geometry.CartesianCoordinate@606d8acfgeometry.CartesianCoordinate@782830e)

0 Answers0