I have to create a quadrilateral program for school where you put in two points and find the area. For the Public double getArea() part it says "return type double is not compatible with void" How do I fix it?

Main class

public class Point {
    double x;
    double y;

public Point(double pX, double pY){
//   this.x = x;
//   this.y = y;
    x = pX;
    y = pY;
}
public void setX (double pX){
//    this.x = x;
    x = pX;
}
public void setY (double pY){
//    this.y = y;
    y = pY;
}
public double getX(){
    return x;
}
public double getY(){
    return y;
}
    @Override
public String toString(){
    return String.format("(" + x + "," + y + ")");
}
}

Quadrilateral class

Trapezoid(double ptX,double ptY){
super(ptX,ptY);
}

public double getArea(){
    return (x*y)/2;
}

    @Override
public String toString(){
 return String.format ("Trapezoid coords: " + "(" + x + "," + y + ")",
         "Area: " + getArea());

OK, before you go on with this, cosider for a moment: is a Quadrilateral an example or special case of a Point, or does it have points as its properties? If the latter, how many Points do you need to represent the Quadrilateral, and how many double values are you passing to the Quadrilateral constructor?

Looking at the getArea() method, what is the formula for computing the area of a Quadrilateral, and do derive the necessary line segment sizes from a pair of Points?

The quadierlateral is the last part where I put in all the info. The points is what gets and sets the x and y variables. And I am passing doubles for 4 shapes.

So much for the Socratic approach, I will be a bit more direct this time: there are issues with your code design above and beyond the error message you've posted. First off, you only posted part of the code for the second class, which makes it harder for us to judge where the problem is occurring; we can't tell which class Trapezoid inherits from. It looks as if it inherits from Point, which would be incorrect: a subclass should always be a specific case of the parent class, whereas a Trapezoid is not a single Point but a collection of Points which define a type of quadrilateral. Properly speaking, it is Quadrilateral that Trapezoid should be inheriting from, but you seem to be going in the opposite direction, making Trapezoid the parent of Quadrilateral.

The other point is that you are passing just two doubles - which define one Point - to the c'tor of Trapezoid, which isn't sufficient information to define a Trapezoid. In fact, given that a Trapezoid has two sized of matching length and two of differing length, it is safe to say that two Points would not be enough to define a Trapezoid, either; you could define a Rectangle with that much information, if you assume that one of the Points is the upper left and the other the lower right (for example), but that depends on the regularity of the Rectangle's sides. With less regular quadrilaterals, you would be better off defining an origin point, and a set of LineSegment objects (which would consist of a pair of Point objects each).

As for getArea(), the formula you are using is simply wrong. You need to get the length of the two matching opposite sides, and multiply that by the long side and the short side. Before you can do that, however, you need the positions of the defining points in space; which in turn means you would have to have the Trapezoid class defined correctly, which as I've said, you don't.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.