...

/

Solution Review: Implement Area and Perimeter Methods

Solution Review: Implement Area and Perimeter Methods

This lesson discusses how to calculate the area and perimeter of a rectangle.

We'll cover the following...

Solution:

The area() and perimeter() methods are written in lines 17-21. They simply take the values of width() and height() and perform the following calculations on them:

Area=widthheightArea = width*height

Perimeter=2width+2heightPerimeter = 2*width + 2*height

This is shown in the code below:

Access this course and 1400+ top-rated courses and projects.