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.
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.
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:
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.
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.)
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.
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.