CS 1713 Practice Problems on Drawing Diagrams


  1. Rectangle is a class that has been appropriately written. It has a constructor with 2 double parameters, a width and length in this order. Draw an accurate schematic diagram of the program variables showing the execution of the program.
    double w = 2;
    double x = 5;
    double y = 7;
    Rectangle r1;
    Rectangle r2;
    Rectangle r3;
    r1 = new Rectangle(w, x);
    r2 = new Rectangle(y, w);
    r3 = r2;
    x = r1.getWidth();
    y = r3.getLength();
    r2 = r1;
    r2.setWidth(15);
    w = r1.getWidth();
    r3 = r1;
    y = r3.getLength();
    x = r1.getWidth();
    
    solution

  2. Draw an accurate schematic diagram of the program variables showing the execution of the program.
    char[][] board;
    char xChar = 'x';
    char oChar = 'o';
    char emptyChar = '!';
    board = new char[3][3];
    for (int i=0;i<board.length;i++)
       for (int j=0;i<board[i].length;j++)
          board[i][j] =  emptyChar;
    board[1][1] = xChar;
    board[0][2] = oChar;
    emptyChar = '?';
    board[2] = board[1];
    
    solution