There is a task:

public void enlarge(int nx, int ny) 

Increases the sides of the Rectangle by (nx, ny) times while maintaining the coordinates of the left upper vertex.

There is a test class to check:

 public class TestRectangle { @Test public void testEnlargeRectangle() { Rectangle rect = new Rectangle(10, 20, 30, 40); rect.enlarge(3, 5); assertEquals(10, rect.getTopLeft().getX()); assertEquals(20, rect.getTopLeft().getY()); assertEquals(70, rect.getBottomRight().getX()); assertEquals(120, rect.getBottomRight().getY()); } } 

I honestly do not fully understand the task. I need to leave the top left vertex in place and just move the bottom right corner of the rectangle, and as a result it will stretch. How to figure it out?

  • 2
    And what, the phrase "Increases the sides of the Rectangle in (nx, ny) times while maintaining the coordinates of the left upper vertex" can be understood in different ways? - Dmitriy

1 answer 1

  1. Calculate the width of the rectangle (right side - left side)
  2. Increase width N times
  3. Update the right side (left side + new width)

Repeat for height.