Challenge 2: Implement Getter Methods

This lesson covers a challenge on getter functions and how to create them.

Problem Statement

Implement the width() and height() methods which return, respectively, the width and height of a rectangle. The tests that follow will create two objects—instances of Rectangle to test the calculations.

Input

A class Rectangle with constructor having the rectangle coordinates x1, y1, x2, and y2 respectively

Output

The width and height of the rectangle

Sample Input

x1 = 2, y1 = 7, x2 = 8, y2 = 4

Sample Output

height = 3, width = 6

Get hands-on with 1000+ tech skills courses.