FunctionRacerProblemsRace

Rectangle on the Table

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Rectangle for a rectangle that lies flat on a table and has a width and a height. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

Rectangle(3, 2)
area() returns 6
perimeter() returns 10
widen(2)
area() returns 10
turn()
fits_in(2, 5) returns true
fits_in(5, 2) returns false

The rectangle starts 3 wide and 2 high: area 6, perimeter 10. Widened by 2 it is 5 by 2, with area 10. After the turn it is 2 wide and 5 high, so it fits a 2 by 5 frame but not a 5 by 2 frame.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems