CS111 Lab Recursion Programming Problems

NestedWindowWorld

In NestedWindowWorld, WindowBuilders build nested window patterns. We can specify the size of the initial window (ie the length of one side -- all windows are squares) and the number of levels of nesting. When we create a WindowBuilder wanda, she starts at a specific place with her pen down and facing the right. If we ask her to build a window with fewer than one level of nesting, she does nothing. She builds a one level window pattern with the bottom left corner of the window at her starting position. Regardless of the number of levels of nesting in the window pattern she builds, wanda stands in her initial position facing her initial direction when she is finished. The following pictures illustrate the result from asking wanda to build windows patterns with different levels of nesting.


wanda.buildDiagonallyNestedWindows(256, 1);


wanda.buildDiagonallyNestedWindows(256, 2);


wanda.buildDiagonallyNestedWindows(256, 3);


wanda.buildDiagonallyNestedWindows(256, 4);

Our task is to fill in the code for the buildDiagonallyNestedWindows method in the WindowBuilder class. The following skeleton is provided for us.

   
public void buildDiagonallyNestedWindows (double size, int levels) {
   
  System.out.println("buildDiagonallyNestedWindows("+size+", "+levels+");");
   
  // add your code here
   
}
   
   

We may also want to define auxiliary methods in the WindowBuilder class. We should not need to modify the NestedWindowWorld class in order for our code to work. However, we may modify it during testing.