Problem Set 3 FAQ
  1. In Part II, is it possible that some of the components of the figure will not require nested loops?

    Yes. If a given component is always one line in height -- regardless of the value of the scale factor -- you may not need nested loops to represent it. Rather, one or more non-nested for loops can be used for whatever repeated characters occur within the line. One example of this in our DrawTorch program is the rim of the torch handle, which is always one line in height. See the drawRim() method for the actual code.

    However, multi-line components of the figure (e.g., the flame or handle of the torch) must be implemented using nested loops. Don't forget that methods with parameters are not allowed in this assignment.

  2. In Part II, I'm trying to use a nested loop to draw a portion of the figure in which the number of occurrences of a given character changes from line to line. I can't seem to get it to work. Do you have any hints?

    If the number of occurrences changes from line to line, make sure that you have developed a formula for how the number of occurrences is related to the line number, and that you are using that formula in the header of the nested loop. See the notes -- and question 3 of Part I -- for examples of how to use a table to develop the necessary formula.

    Also, don't forget that your nested loops should be simple repetition loops that follow this template (or a similar one):

        for (int i = 0; i < N; i++) {
            // line or line(s) to repeat
        }
    
    where you replace N with the number of repetitions -- which may be a formula based on the line number.

  3. In Part II, several of my nested for loops are similar to each other. I even have nested for loops that are identical. Is that okay, or should I somehow be using a method to eliminate the duplication?

    Because we're not allowing you to use methods with parameters, it's not possible to use a single method for nested loops that are similar. For example, in our DrawTorch program, we have several different nested loops that print spaces, such as:

        for (int i = 0; i < 4 - line; i++) {
            System.out.print(" ");
        }
    
    and
        for (int i = 0; i < line - 1; i++) {
            System.out.print(" ");
        }
    
    However, because these loops are not identical, we can't use a method without parameters to replace them. Instead, we would need a parameter specifying how many spaces to print.

    If you have two identical nested loops, you could use a separate method to eliminate the duplication, but it isn't strictly necessary to do this if the only repeated code is a nested loop.

    However, you should look for other places where you can use static methods:

    • to capture the structure of your program. See our DrawTorch program for examples of this. It's available in its entirety in the examples associated with the lecture notes on methods on the course website. The case study at the end of Chapter 2 of the textbook is another good example to use as a model.

    • to avoid duplication of larger blocks of code. For example, if two portions of the figure are identical, you should use a single method for both of them.


  4. In Part II, I'm having trouble figuring out how to use the scale-factor constant to make my existing code scaleable. Do you have any suggestions?

    You can use tables here as well. For example, consider our DrawTorch program. When its scale factor is 2, the top of the torch handle looks like this:

    |::::::|
     |::::|
    
    We saw in lecture that the formula for the number of colons on a given line is
        colons = 8 - 2*line
    
    When the scale factor is 3, the top of the torch handle looks like this:
    |::::::::::|
     |::::::::|
      |::::::|
    
    If we determined the formula for the number of colons at this size (using the same approach taken in lecture), we would get the following formula:
        colons = 12 - 2*line
    
    Given these two formulas, we can determine how the various numbers in the formulas depend on the value of the scale factor. First, we notice that both formulas multiply the line number by 2. This means that the 2 does not depend on the scale factor. The other number in the formula does depened on the scale factor, and we can determine how by using the following table:
        scale-factor   first number in formula
             2              8
             3              12
    
    Using the same procedure shown in lecture, we can see that the first number in the formula is 4 times the scale factor. Thus, the general formula for the number of colons is:
        colons = 4*SCALE_FACTOR - 2*line
    
    and thus we would replace 8 - 2*line in DrawTorch with 4*SCALE_FACTOR - 2*line in DrawTorch2. (Note: In those programs, the name of the constant was actually TOP_HEIGHT, not SCALE_FACTOR.)

  5. Is it a problem if I accidentally uploaded extra files using WebSubmit? I can't seem to find a way to delete them.

    This isn't a problem. We will ignore any files other than the two files with the filenames that we specified. Make sure that you have uploaded files with those names, and that they contain the final version of your work. The notes at the bottom of the problem set explain how you can doublecheck your submission, and we strongly recommend that you do so.

  6. I uploaded one version of my Java file using WebSubmit, but now I'd like to replace it with an updated version of the file. Can I do that?

    Yes! If you upload a file with the same name as a previously uploaded file, the new file will replace the old one. In fact, WebSubmit can be a useful way to make backups of your work while you're in the middle of working on an assignment. Simply make periodic uploads to WebSubmit for safekeeping.