Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Geometric Figure

dickersonka
dickersonka 


1. (#10 on page 598) Create an abstract class called GeometricFigure. Each figure includes a height, a width, a figure type, and an area. Include an abstract method to determine the area of the figure. Create two subclasses called Square and Triangle. Create an application that demonstrates creating objects of both subclasses, and store them in an array. Save the files as GeometricFigure.java, Square.java, Triangle.java, and UseGeometric.java. 2. (#11 on page 598) Modify Exercise 10, adding an interface called SidedObject that contains a method called displaySides(); this method displays the number of sides the object possesses. Modify the GeometricFigure subclasses to include the use of the interface to display the number of sides of the figure. Create an application that demonstrates the use of both subclasses. Save the files as GeometricFigure2.java, Square2.java, Triangle2. java, SidedObject.java, and UseGeometric2.java. Attachments
Tags Clarifications

Answers

Java - Geometric Figure - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Geometric Figure assignment including source and comments Attachments
GeometricFigurePart1.zip (1 K) Download
Preview
parent constructor super(height, width, "Square"); } @Override public double area() { //height * width

Preview
* Create triangle * @param height height of triangle * @param width width of triangle */

Preview
area(); /** * Get height * @return height */ public int getHeight() { return height; } /** * Set height * @param height height */ public void setHeight(int height) { this.height = height; }

Preview
public static void main(String[] args){ //create array of geometric figure GeometricFigure[] figures = new GeometricFigure[2]; //create square Square square =

GeometricFigurePart2.zip (2 K) Download
Preview
public class Square2 extends GeometricFigure2 implements SidedObject{ /** * Create square * @param height height of square * @param width width

Preview
{ return width; } /** * Set width * @param width width */ public void setWidth(int width) { this.width = width; } /** * Get figure type * @return figure type */ public String

Preview
* Display sides

Preview
GeometricFigure2[] figures = new GeometricFigure2[2]; //create square Square2 square = new Square2(10, 10); //create triangle Triangle2 triangle = new Triangle2(4, 15);

Preview
/** * Create triangle * @param height height of triangle * @param width width of triangle */ public Triangle2(int

GeometricFigure_output1.png (2 K) Download Preview

GeometricFigure_output2.png (3 K) Download Preview

Screenshots
Screenshot
Screenshot
Purchase Answer