Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the Circle and the Rectangle classes in the folder P1 using the instructions below. You are NOT allowed to create any other classes, additional

Implement the Circle and the Rectangle classes in the folder P1 using the instructions below. You are NOT allowed to create any other classes, additional instance variables, or make any changes to classes other than Circle and Rectangle. You will lose points if you do.

For the Circle class, implement the following:

A private double instance variable m_radius. A constructor that takes two parameters (in the order of color, radius). It should use the

parameter for radius to set the m_radius instance variable and then explicitly call the parent class constructor using the super keyword and pass in the color parameter. A method that overrides the calcArea method of the superclass and calculates the area of the circle. The area of a circle can be calculated as 3.14 ^2 (where is the radius). A method that overrides the calcPerimeter method of the superclass and calculates the perimeter of the circle. The perimeter of a circle can be calculated as 2 3.14 (where r is the radius).

For the Rectangle class, create the following:

Two private double instance variables m_width and m_length. A constructor that takes three parameters (in the order of color, width, length). It should use the parameters for width and length to set the instance variables and then explicitly call the parent class constructor using the super keyword and pass in the color parameter. A method that overrides the calcArea method of the superclass and calculates the area of the rectangle. The area of a rectangle can be calculated as width height.

A method that overrides the calcPerimeter method of the superclass and calculates the perimeter of the rectangle. The perimeter of a rectangle can be calculated as 2 (width height).

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

Students also viewed these Databases questions