Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the answers clear and easy to be read and please sipirt the answers so It would be in order Your mission is to

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Please write the answers clear and easy to be read and please sipirt the answers so It would be in order Your mission is to create eight files, described below, which taken together will comprise an object oriented model of several shapes. I am uploading images of the first three files from the ist below -to get started, you may type what you see into your IDE to knock off the first three points... 1 point: Create an interface called Shape with three method signatures: getArea) and getPerimeter), which will both return a double, and printNumSides), which will return a String. Remember, an interface doesn't need to have any concrete code in it --you're just setting up expectations for later. (See the 'Sellable' for example on p. 77 of the textbook.) (See the downloadable png image... 1 point: Create a class Rectangle that implements the Shape interface. It should have two data fields of type double called width and height, and a constructor that takes the parameters width and height. It should, of course, implement the three Shape methods mentioned above. (See the downloadable png image...) 1 point: Create a class Square that extends the Rectangle interface. Square is a subclass (or child) of Rectangle. The only code Square needs is a constructor that takes one parameter of type double: side. You can then use that value for side to initialize super.width and super.height. (See the downloadable png image...) 2 point: Create a class Circle that implements the Shape interface. It should have a data field called radius, and in addition to implementing the Shape methods, it should have the method getDiameter). 1 point: Create an abstract class Triangle that implements the Shape interface. Because this class is abstract, it hardly needs to have any code in it -- that could all be done by any child class that would extend Triangle. However, we know that all triangles have three sides, so make the Triangle class implement the printNumSides) method by returning the String: "Three sides! That way, you don't have to write the same printNumSides) method each time you do write a class that extends Triangle. Also, all triangles have a base and a height, so create those data fields in Triangle. ALSO... the area of any triangle can be computed with the base and height, so implement that method in the Triangle class too. 1 point: Create a class EquilateralTriangle that extends Triangle. The constructor will just take one argument: side. It will be your job to make sure that super.base and super.height get initialized in this constructor. You will also need to implement the getPerimeter) method here. 1 point: Create a class RightTriangle that extends Triangle. The constructor for this class will take two parameters: side A and side B. Side C would be the hypotenuse, which you should compute with another method before you can implement the getPerimeter) method. Make getHypotenuse() a public method, so that you can use in other classes too. 1 point: Use good* Javadoc comments to describe each of your classes and methods. *Your TA is the judge of how good the comments are-make it easy for them to read an understand what you are trying to do. 1 point: Create a class ShapeDemo to show off. This class should have the main) method, as s several Shape objects you should create to demonstrate the usage. (See example below.) Put all 8 of these files (Shape.java, Rectangle.java, Square.java, Circle.java, Triangle.java, EquilateralTriangle.java, RightTriangle.java, and ShapeDemo.java) into a package (folder) called Example I have instantiated five shape objects and printed some info about them in the example run of my demo program below. You don't need to copy my example exactly, but come up with a few tests of your own; at least five. Experiment with some different shapes, and explain in the print statements what you found. I made a Circle of type Circle with radius of 2 The area is 12.566370614359172 The circumference is 12.566370614359172 Infinate sides The diameter is 4.0 I made a Shape of type Circle with radius of 3. The area is 28.274333882308138 The circumference is 18.84955592153876 Infinate sides Well, I can't get the diameter of a Shape.'(I tried.) But since I know the object being referenced is a Circle, I can cast it to a Circle, and then I can get the diameter of it... .. .And the diameter is 6.0 Made another Shape of type EquilateralTriangle; side length of 4 The area is 6.928203230275509 The perimeter is 12.0 Made a RightTriangle of type RightTriangle: side lengths 3, 4. The area is 6.0 Three sides The hypotenuse: 5.0 Made a Shape of type Square. Side length 5 The area is 25.0 The perimeter is 20.0 Four sides backage prj02; A model of a rectangle shape k@author danieldefrance public class Rectangle implements Shape // Fields protected double width; protected double height; // Constructors /kok * Constructs a new rectangle instance with a default of 0 for both width and height public Rectangle) * Constructs a new rectangle instance * @param W The width of the rectangle * @param h The height of the rectangle public Rectangle(double w, double h) f this.widthw; this.height-h; // Methods 0verride public double getArea() f return width * height; 0verride public double getPerimeter) return 2 * width + 2 * height; GOverride public String printNumSides) { return "Four sides"; package prj02; An interface for a geometric shape. k@author danieldef rance public interface Shape t * The area of the shape *@return area of the shape k/ public double getArea); * The distance around the outside of the shape *@return perimeter of the shape public double getPerimeter) * The number of sides that form the shape @return number of sides public String printNumSides) 1 package prj02; 4 A model of a square shape 5 @author danieldefrance 8 public class Square extends Rectangle f 9 10 /1 Fields none 12 13 14 ** 15 16 17 18 public Square (double side)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions