CS 312 Assignment 2 - Using Loops To Draw Complex Figures
Programming Assignment 2: Individual Assignment. You must complete this assignment by yourself. You cannot copy code from anyone else in the class or from someone outside of the class. You cannot show your code to any other student in the class. You are encouraged to get help from the instructional staff. You may post general questions to Piazza. Do not post more than 1 line of code to Piazza when asking a question.
Placed online: Tuesday, January 25
20 points, ~2% of total grade
Due: no later than 11 pm, Thursday, February 10
General Assignment Requirements
Description: The purposes of this assignment are:
Create a program that produces an ASCII art representation of the UT Tower. he output will vary based on a constant in the program. By simply changing the constant the output will change (somewhat) dramatically. In the end your program must match the outputs shown for the give value of the SIZE constant EXACTLY.
Here is the program output with the constant named SIZE set to 3.
#####
|||||
|||||
|||||
|||||
#####
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
|-O-O-O-|
~~~~~~~~~
/"'"'"'"'"'"'"'"'"'"'"'"'"\
/"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
When the SIZE constant is changed to 4, the following output is produced:
#######
|||||||
|||||||
|||||||
|||||||
|||||||
|||||||
#######
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
|-O-O-O-O-|
~~~~~~~~~~~
/"'"'"'"'"'"'"'"'"'"'"'"'"'"'"\
/"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"\
/"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
/"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"O"\
This assignment is meant to give you practice with the constructs from chapters 1 and 2 of the textbook. (println and print statements, static methods, decomposition, loops, nested loops, and class / program constants) This will require you to create nested for loops with print and println statements that use the class constant and local variables. You may not use anything besides the constructs from chapters 1 and 2. Specifically you MAY NOT use parameters or methods that return values (chapter 3 in the book) on this assignment or conditional statements (if, if/else statements)
You shall use static methods to structure your solution. You shall avoid significant redundancy and you shall structure your program in such a way that the methods match the structure of the output itself. You are required to properly indent your source code and will lose points if your indenting is not readable and consistent You should localize variables whenever possible. You shall have class constant named SIZE.
Do not alter any part of the following line except the actual literal int you use such as 2, 3, 4, 5, and so forth,
public static final int SIZE = 3;
Note how the SIZE constant will determine several things such as the height of the top of the tower, the number of floors, the number of lines that make up the top of the base, and the number of lines in the bottom of the base. Note how the SIZE constant is used to determine the number of windows (the capital Os) in the floors of the main tower and the base and things such as the number of spaces before the lines at the top of the tower and the main part of the tower.
The SIZE constant will always be greater than or equal to 2.
You may add
other program constants if you use them in multiple methods, However, if
you add any constants DO NOT include the word SIZE (including any
variations on capitilazations such as sIZE, etc.) in he name of that constant.
So for example:
public static final int BASE_SIZE2 = 5; // BAD NAME FOR
ASSIGMENT 2
public static final int BASE_SZE_2 = 5; // Okay, name does
not contain SIZE exactly.
The reason for the limitations is if you do you include size in a program constant name then your code will flummox our grading script and you will lose correctness points.
As a reference my solution consists of approximately 140 lines including blank lines and comments. The problem is broken up into 7 - 9 methods not counting the main method.
Complete the comment at the beginning of your Tower.java program. Include a comment for each method you write explaining the purpose of that method.
On any given execution your program will produce just one version of this figure, but it should be possible to change the value of the program constant to have your program produce a Tower of a different size. Here are files with the expected out for size 2, size 3, size 4, size 5, size 6, and size 7. Your output must match these exactly for a given size or you will lose points for correctness. Use a diff tool such as the one at this website (https://www.diffchecker.com/) to ensure your program produces the correct output.
The last line of the drawing is printed out with a println statement. I recommend you downloading the above files by putting your cursor over the link and bringing up a context menu (right click on Windows, control click on Macs) and select the option to download the file. Web browsers often delete that last carriage return / newline when displaying the file.
If you are using BlueJ: Recall, Bluej truncates the output in the console to approximately 20 lines. This results in your output being cutoff in some cases. You can change this. Run your program. In the Options menu on the Terminal Window that pops up when you run your program, ensure ensure the menu options Clear screen at method call and Unlimited buffering are checked. After making these changes you may have to stop and restart BlueJ for the choice to take effect. Many other IDEs also limit the amount of output to standard output (where output from println is sent) and you may need to adjust this in your IDE to allow unlimited output to standard out. Other IDES suffer the same problem. Search how to have unlimited buffering in you IDE console so you can see all your programs output.
When finished turn in your Tower.java file via Canvas.
| Provided File | Responsibility |
| Tower.java (Provided shell) | You and me. (Okay, mostly you.) |
Checklist: Did you remember to:
Tips: Development strategy. The program is not trivial and will take some time to do. You should complete it in stages and may have to spend several hours on it. Work with pen and paper before writing code. Some ideas:
Here is some excellent advice from a former student, Jeff Lyon, on how to approach this assignment and what to do if you get stuck.
As you can see, you really need to pay attention to details on this assignment. And that is true of computer science and software development in general.