Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My code has problems when it compiles. Please help Write an inheritance hierarch

ID: 3622572 • Letter: M

Question

My code has problems when it compiles. Please help


Write an inheritance hierarchy for class Quadrilateral, Trapezoid, Parallelogram, Rectangle, and Square. Use Quadrilateral as the super class of the hierarchy. Make the hierarchy as deep I.e., as many levels) as possible. Specify the instance variables and methods for each class. The private data of the Quadrilateral should be the x-y coordinate pairs for the four end-points of the Quadrilateral. Write a program that instantiate objects of you classes and outputs each object area (except Quadrilateral)


//Point class
public class Point
{
private double x, y;

public Point( double xCoordinate, double yCoordinate )

{
x = xCoordinate;
y = yCoordinate;
}
public double getX()

{
return x;
}

public double getY()

{
return y;
}
public String toString()

{
return "( " + getX() + ", " + getY() + " )";
}
} // end class Point

public class Quadrilateral
{
Point point1, point2, point3, point4;

public Quadrilateral( double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4 )

{
point1 = new Point( x1, y1 );
point2 = new Point( x2, y2 );
point3 = new Point( x3, y3 );
point4 = new Point( x4, y4 );
}
public Point getPoint1()

{
return point1;
}
public Point getPoint2()

{
return point2;
}
public Point getPoint3()

{
return point3;
}
public Point getPoint4()

{
return point4;
}
public String toString()

{
return "Coordinates of Quadrilateral are: " + printCoordinates();
}
public String printCoordinates()

{
return point1.toString() + ", " + point2.toString() + ", " +
point3.toString() + ", " + point4.toString();
}
} // end class Quadrilateral


public class Trapazoid extends Quadrilateral
{
double height;

public Trapazoid( double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4 )
9
{
super( x1, y1, x2, y2, x3, y3, x4, y4 );
}
public double getHeight()

{
if ( getPoint1().getY() == getPoint2().getY() )
return Math.abs( getPoint2().getY() - getPoint3().getY() );
else
return Math.abs( getPoint1().getY() - getPoint2().getY() );
}

public double getArea()

{
return getSumOfTwoSides() * getHeight() / 2.0;
}
public double getSumOfTwoSides()

{
if ( getPoint1().getY() == getPoint2().getY() )
return Math.abs( getPoint1().getX() - getPoint2().getX() ) +
Math.abs( getPoint3().getX() - getPoint4().getX() );
else
return Math.abs( getPoint2().getX() - getPoint3().getX() ) +
Math.abs( getPoint4().getX() - getPoint1().getX() );
}
public String toString()

{
return " Coordinates of Trapazoid are: " + printCoordinates() +
" Height is: " + getHeight() + " Area is: " + getArea();
}

} // end class Trapazoid



// Class Parallelogram definition

public class Parallelogram extends Trapazoid
{

public Parallelogram( double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4 )

{
super( x1, y1, x2, y2, x3, y3, x4, y4 );
}

public double getWidth()

{
if ( getPoint1().getY() == getPoint2().getY() )
return Math.abs( getPoint1().getX() - getPoint2().getX() );
else
return Math.abs( getPoint2().getX() - getPoint3().getX() );
}

public String toString()

{
return " Coordinates of Parallelogram are: " +
printCoordinates() + " Width is: " + getWidth() +
" Height is: " + getHeight() + " Area is: " + getArea();
}

} // end class Parallelogram


// Class Rectangle definition
public class Rectangle extends Parallelogram
{

public Rectangle( double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4 )

{
super( x1, y1, x2, y2, x3, y3, x4, y4 );
}

public String toString()

{
return " Coordinates of Rectangle are: " + printCoordinates() +
" Width is: " + getWidth() + " Height is: " + getHeight() +
" Area is: " + getArea();
}
} // end class Rectangle


// Class Square definition

public class Square extends Parallelogram
{

public Square( double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4 )
8
{
super( x1, y1, x2, y2, x3, y3, x4, y4 );
}
public String toString()

{
return " Coordinates of Square are: " + printCoordinates() +
" Side is: " + getHeight() + " Area is: " + getArea();
}
} // end class Square

Explanation / Answer

Dear... Am giving you the java code using Applet. import java.applet.Applet; import javax.swing.JOptionPane; class Quadrilateral { private int x[ ]=new int[10]; int i; String s[ ]={"x1= ","y1= ","x2= ","y2= ","x3=","y3= ","x4= ","y= 4"},st; Quadrilateral(int b[ ]) { for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote