Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Inheritance and extends Overridden methods Abstract class and methods (in Shape parent class) Inherited method (toString() and output()) super method Create an application that, given

Inheritance and extends

Overridden methods

Abstract class and methods (in Shape parent class)

Inherited method (toString() and output())

super method

Create an application that, given certain parameters for a shape, will return the shape's area and perimeter in meters. This application should be extensible. There should be a generic shape class that performs the work of printing the area and perimeter values. Create the Shape generic class and only one specific shape from the list below that extends the shape class. The main method for the project should come from the specific extended class, not Shape.

Create a new project.

Create an abstract Shape class. This class will only be a model for other shapes to come.

Create a field (attribute) called type and a getter called getType(). This field will hold the type of the shapes when new, concrete shapes are created.

Create three abstract getters for area, perimeter and parameters. There is no need to create fields for these values.

Create a default constructor and a constructor that accepts the shape type as a parameter.

Create an abstract requestInput() method with return type void.

Create an toString() method that displays the following information:

Details for with : The area is meters. The perimeter is meters.

Replace the values in the angle braces with calls to getter methods. Create an output() method that displays the toString() information, either in a JOptionPane or using System.out.println(). Create one, and only one, of the shapes from the table below or create one of your own. The new type class must inherit from the Shape class. Use the value Math.PI for . There is a Math.tan() method that will compute tangent.

Type

Input / Parameters

Area Calculation

Perimeter Calculation

Circle radius radius radius 2 radius
Rectangle width, height width height 2 (width + height)
RegularPolygon sides, length (sides length length) / (4 tan( / sides)) sides length

Create the input parameters as attributes with appropriate types and create getters and setters for each, implementing the getters and setters from Shape. These should be standard getters and setters. DO NOT request input from the user in the getters and setters. That will be accomplished in the next step in the requestInput() method.

Implement requestInput() to ask for the input parameters, overriding Shape's requestInput() method. The getParameterString() method creates a String of input parameters and their corresponding values. Call the getter methods for each of the input parameters to print the value.

Implement the getters for area and perimeter.

DO NOT implement the output method in the child class. Let the class inherit this method and the toString() method from the Shape class. Since the getters are defined in the Shape class and overridden in the child shape, the correct value will display for the shape created.

Create a default constructor that calls the Shape class's constructor to set the type. Use the super method.

Create a main method that creates the child shape object, calls the requestInput() and output methods. Ask the user if they want to try again and loop. Make sure this is the main method selected when creating the jar file.

As required for all assignments from now on

validate the proper functionality using the example answers below and review the Concepts and Ideas checklist

format the code

add a comment at the top of the file that reads @ author and your name

build the javadocs

Verify that the jar file contains source and class files and the MANIFEST.MF file contains a Main-Class. See the Resources section for Configuring Eclipse to view Jar files.

Run the application from the jar file, either from the command line using java -jar jarfilename or from Eclipse. See the Resources section for Configuring Eclipse to run Jar files.

submit the jar file in the Assignment section of BlackBoard under View/Complete Assignment for this assignment.

Example:

The results in the following examples do not have to match exactly, though they should be accurate through two places to the right of the decimal. Only one concrete shape implementation is required for this assignment, however, you are welcome to implement more.

Circle

Please enter a radius in meters: 3

Details for circle

with radius 3.0:

The area is 28.274333882308138 meters.

The perimeter is 18.84955592153876 meters.

Rectangle

Please enter a width: 10

Please enter a height: 20

Details for rectangle

with width: 10.0 height: 20.0:

The area is 200.0 meters.

The perimeter is 60.0 meters.

RegularPolygon

Please enter number of sides: 6

Please enter side length: 1

Details for polygon

with sides: 6.0 length: 1.0:

The area is 2.598076211353316 meters.

The perimeter is 6.0 meters.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

7. What traps should she avoid?

Answered: 1 week ago

Question

5. What decision-making model would you advocate to this person?

Answered: 1 week ago

Question

6. What data will she need?

Answered: 1 week ago