Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes

Write the following well-documented (commented) program.

Create a class called Shape that has a method for printing the area and the perimeter.

Create three classes (Square, Rectangle, and Circle) which inherit from it.

  • Square will have one instance variable for the length.
  • Rectangle will have two instance variables for the width and height.
  • Circle will have one instance variable for the radius.
  • The three classes will have methods for computing the area and perimeter of its corresponding shape.

Write a main method to test your program that uses objects of the classes you created.

  • It should ask the user for the length of a square, the width and height of a rectangle, and the radius of a circle.
  • It should then print out the area and perimeter of the three shapes.

A sample run would be as follows.

Enter the length of a square: 7 The area is 49.00 and perimeter is 28.00. Enter the width of a rectangle: 5 Enter the height of a rectangle: 6 The area is 30.00 and perimeter is 22.00. Enter the radius of a circle: 4 The area is 50.24 and perimeter is 25.12.

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

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

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions