Question: Hello, I am having trouble with my code on part 6. I am trying to create a trapezoid and circle. I know the return area

Hello, I am having trouble with my code on part 6. I am trying to create a trapezoid and circle. I know the return area calculation in the Circle and Trapezoid classes are incorrect, but there are also errors in the Test class.

Hello, I am having trouble with my code on part 6. I

//Test

package test;

import base.ShapeBase; import shape.Circle; import shape.Rectangle; import shape.Trapezoid; import shape.Triangle;

public class Test { private static void displayArea(ShapeBase shape) { // Show polymorphic in action by getting the Shapes Name and Area System.out.println("This is a shape named " + shape.getName() + " with an area of " + shape.calculateArea()); }

public static void main(String[] args) { // Create an array of Base Shapes and initialize to specific Shapes ShapeBase[] shapes = new ShapeBase[4]; shapes[0] = new Rectangle("Rectangle", 10, 200); shapes[1] = new Triangle("Triangle", 10, 50); shapes[2] = new Circle("Circle", 10, 100); shapes[3] = new Trapezoid("Trapezoid", 5, 300); //For all Shapes display its area for(int x = 0; x

}

}

======================================

//ShapeBase

package base;

public class ShapeBase implements ShapeInterface { protected String name; protected int width, height; public ShapeBase(String name, int width, int height) { this.name = name; this.width = width; this.height = height; } public String getName() { return this.name; } @Override public int calculateArea() { return -1; } }

=================================================

//ShapeInterface

package base;

public interface ShapeInterface { int calculateArea();

}

================================

//Circle

package shape;

import base.ShapeBase;

public class Circle extends ShapeBase { public Circle(String name, int width, int height) { super(name, width, height); } @Override public int calculateArea() { return width * height; }

}

====================================

//Rectangle

package shape;

import base.ShapeBase;

public class Rectangle extends ShapeBase { public Rectangle(String name, int width, int height) { super(name, width, height); } @Override public int calculateArea() { return width * height; }

}

====================================

//Trapezoid

package shape;

import base.ShapeBase;

public class Trapezoid extends ShapeBase { public Trapezoid(String name, int width, int height) { super(name, width, height); } @Override public int calculateArea() { return width * height/2; }

}

===========================

//Triangle

package shape;

import base.ShapeBase;

public class Triangle extends ShapeBase { public Triangle(String name, int width, int height) { super(name, width, height); } @Override public int calculateArea() { return width * height/2; }

}

shine ! .. aku FATRE I. -.. ***. livssti Two beste herrera I. . LIETTERIN UP : ...M VFX: * VIP STAN a Cavax.xx try III Niveau HIM140 WESTERN VENTAJI FIN AR el .1.1.1 L 1.1 | . RAJ VA ... LELLE. LED.U...... Lakas ELLELNARRARA DI Cw12V Canned Tatuit sex wit. CHRY: Care stywisted Trwirawat i 101 #hbd #d 14 whatiw YU. WWE RIPID. Tirnir 2.Core Cunet 11 GRAND CANYON . SA Irart Can F.3de Lacinta 1. Sabah 12 TRIER ....lazyka: 1. America TAXA : CHEMICAL Traws Tritori vivite! CYTHvarrenton T 7 WY ...IHL lubrrr...s IRREVERE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!