JAVA CODE: class quad{ public static void main(String args[] ){ Quadrilateral quadrilateral = new Quadrilateral( 1.1, 1.2, 6.6, 2.8, 6.2, 9.9, 2.2, 7.4 ); Trapezoid trapezoid = new Trapezoid (0.0, 0.0, 10.0, 0.0, 8.0, 5.0, 3.3, 5.0 ); Parallelogram parallelogram = new Parallelogram (5.0, 5.0, 11.0, 5.0, 12.0, 20.0, 6.0, 20.0 ); Rectagle rectagle = new Rectagle(17.0, 14.0, 30.0, 14.0, 30.0, 28.0, 17.0, 28.0 ); Square square = new Square( 4.0, 0.0, 8.0, 0.0, 8.0, 4.0, 4.0, 4.0 ); System.out.printf("%s %s %s %s %s\n", quadrilateral, trapezoid, parallelogram, rectagle, square ); } } class Point{ private double x; private double 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 String.format( "( %.1f, %.1f)", getX(), getY() ); } } class Quadrilateral { private Point point1; private Point point2; private Point point3; private Point 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 String.format( "%s:\n%s","COORDINATES OF QUADRILATERAL ARE: ", getCoordinatesAsString() ); } public String getCoordinatesAsString(){ return String.format("%s,%s,%s,%s,%s\n", point1, point2, point3,point4 ); } } class Trapezoid extends Quadrilateral { private double height; public Trapezoid(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 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 String.format("\n%s:\n%s: %s\n%s: %s\n", "COORDINATES OF TRAPEZOID ARE", getCoordinatesAsString(), "Height is:", getHeight(), "Area is:", getArea() ); } class Parallelogram extends Trapezoid{ 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 String.format( "\n%s:\n%s%s: %s\n%s: %s\n%s: %s\n","COORDINATES OF PARALELLOGRAM ARE:",getCoordinatesAsString(), "Width is", getWidth(),"Height is", getHeight(),"Area is:", getArea() ); } } class Rectagle extends Parallelogram{ public Rectagle( 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 String.format( "\n%s:\n%s%s: %s\n%s: %s\n%s: %s\n","COORDINATES OF RECTAGLE ARE:",getCoordinatesAsString(), "Width is", getWidth(),"Height is", getHeight(),"Area is:", getArea()); } class Square extends Parallelogram{ public Square( 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 String.format( "\n%s:\n%s%s: %s\n%s: %s\n%s: %s\n","COORDINATES OF SQUARE ARE:",getCoordinatesAsString(), "Width is", getWidth(),"Height is", getHeight(),"Area is:", getArea() ); } }
HELLO! PLEASE HELP ME FIX THE ERROR THANKYOU. :)
JAVA CODE:
class quad{
public static void main(String args[] ){
Quadrilateral quadrilateral = new Quadrilateral( 1.1, 1.2, 6.6, 2.8, 6.2, 9.9, 2.2, 7.4 );
Trapezoid trapezoid = new Trapezoid (0.0, 0.0, 10.0, 0.0, 8.0, 5.0, 3.3, 5.0 );
Parallelogram parallelogram = new Parallelogram (5.0, 5.0, 11.0, 5.0, 12.0, 20.0, 6.0, 20.0 );
Rectagle rectagle = new Rectagle(17.0, 14.0, 30.0, 14.0, 30.0, 28.0, 17.0, 28.0 );
Square square = new Square( 4.0, 0.0, 8.0, 0.0, 8.0, 4.0, 4.0, 4.0 );
System.out.printf("%s %s %s %s %s\n", quadrilateral, trapezoid, parallelogram, rectagle, square );
}
}
class Point{
private double x;
private double 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 String.format( "( %.1f, %.1f)", getX(), getY() );
}
}
class Quadrilateral {
private Point point1;
private Point point2;
private Point point3;
private Point 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 String.format( "%s:\n%s","COORDINATES OF QUADRILATERAL ARE: ", getCoordinatesAsString() );
}
public String getCoordinatesAsString(){
return String.format("%s,%s,%s,%s,%s\n", point1, point2, point3,point4 );
}
}
class Trapezoid extends Quadrilateral {
private double height;
public Trapezoid(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 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 String.format("\n%s:\n%s: %s\n%s: %s\n", "COORDINATES OF TRAPEZOID ARE", getCoordinatesAsString(), "Height is:", getHeight(), "Area is:", getArea() );
}
class Parallelogram extends Trapezoid{
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 String.format( "\n%s:\n%s%s: %s\n%s: %s\n%s: %s\n","COORDINATES OF PARALELLOGRAM ARE:",getCoordinatesAsString(), "Width is", getWidth(),"Height is", getHeight(),"Area is:", getArea() );
}
}
class Rectagle extends Parallelogram{
public Rectagle( 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 String.format( "\n%s:\n%s%s: %s\n%s: %s\n%s: %s\n","COORDINATES OF RECTAGLE ARE:",getCoordinatesAsString(), "Width is", getWidth(),"Height is", getHeight(),"Area is:", getArea());
}
class Square extends Parallelogram{
public Square( 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 String.format( "\n%s:\n%s%s: %s\n%s: %s\n%s: %s\n","COORDINATES OF SQUARE ARE:",getCoordinatesAsString(), "Width is", getWidth(),"Height is", getHeight(),"Area is:", getArea() );
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps