CS 305J Assignment, Using Loops

Programming Assignment 3 Individual Assignment. You must complete this assignment by yourself. You cannot work with anyone else in the class or with someone outside of the class. You are encouraged to get help from the instructional staff.

Placed online: Wednesday, September 10
20 points, ~2% of total grade
Due: no later than 11 pm, Thursday, September 18
General Assignment Requirements

Description The purposes of this assignment are:
  1. To decompose a complex problem into simpler parts
  2. To use loops to be able to generalize a problem
  3. To practice writing static methods
  4. To practice using print and println statements
  5. To practice identifying and using appropriate program constants.

Complete a program named Rocket.java. The program is to produce the following output.

     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\
+=*=*=*=*=*=*+
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
+=*=*=*=*=*=*+
|\/\/\/\/\/\/|
|.\/\/..\/\/.|
|..\/....\/..|
|../\..../\..|
|./\/\../\/\.|
|/\/\/\/\/\/\|
+=*=*=*=*=*=*+
     /**\
    //**\\
   ///**\\\
  ////**\\\\
 /////**\\\\\

Your program is to reproduce this output exactly. Getting the correct output is only half of the assignment though. The other half is to create a well structured, general solution. By simply changing the value assigned to a single constant in your program your program should then be able to produce the following output.

             /**\
            //**\\
           ///**\\\
          ////**\\\\
         /////**\\\\\
        //////**\\\\\\
       ///////**\\\\\\\
      ////////**\\\\\\\\
     /////////**\\\\\\\\\
    //////////**\\\\\\\\\\
   ///////////**\\\\\\\\\\\
  ////////////**\\\\\\\\\\\\
 /////////////**\\\\\\\\\\\\\
+=*=*=*=*=*=*=*=*=*=*=*=*=*=*+
|....../\............/\......|
|...../\/\........../\/\.....|
|..../\/\/\......../\/\/\....|
|.../\/\/\/\....../\/\/\/\...|
|../\/\/\/\/\..../\/\/\/\/\..|
|./\/\/\/\/\/\../\/\/\/\/\/\.|
|/\/\/\/\/\/\/\/\/\/\/\/\/\/\|
|\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
|.\/\/\/\/\/\/..\/\/\/\/\/\/.|
|..\/\/\/\/\/....\/\/\/\/\/..|
|...\/\/\/\/......\/\/\/\/...|
|....\/\/\/........\/\/\/....|
|.....\/\/..........\/\/.....|
|......\/............\/......|
+=*=*=*=*=*=*=*=*=*=*=*=*=*=*+
|\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
|.\/\/\/\/\/\/..\/\/\/\/\/\/.|
|..\/\/\/\/\/....\/\/\/\/\/..|
|...\/\/\/\/......\/\/\/\/...|
|....\/\/\/........\/\/\/....|
|.....\/\/..........\/\/.....|
|......\/............\/......|
|....../\............/\......|
|...../\/\........../\/\.....|
|..../\/\/\......../\/\/\....|
|.../\/\/\/\....../\/\/\/\...|
|../\/\/\/\/\..../\/\/\/\/\..|
|./\/\/\/\/\/\../\/\/\/\/\/\.|
|/\/\/\/\/\/\/\/\/\/\/\/\/\/\|
+=*=*=*=*=*=*=*=*=*=*=*=*=*=*+
             /**\
            //**\\
           ///**\\\
          ////**\\\\
         /////**\\\\\
        //////**\\\\\\
       ///////**\\\\\\\
      ////////**\\\\\\\\
     /////////**\\\\\\\\\
    //////////**\\\\\\\\\\
   ///////////**\\\\\\\\\\\
  ////////////**\\\\\\\\\\\\
 /////////////**\\\\\\\\\\\\\

Notice that the various subfigures in the middle of the original, smaller rocket, have a height of 3.  These subfigures have the property that their height determines their width, so you only need one constant for the size of the rocket.  You are to use a class constant to make it possible to change a single number in one place in the program to have it produce a corresponding figure of a different size. The larger rocket has a size of 7.

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 constantsThis will require you to create nested for loops with print and println statements that use the class constant.  If you are interested, you may use the constructs from chapter 3, although you are not required to do so and you will receive no extra credit if you do. (Really, it is okay to not use parameters, and if you have never programmed before I strongly urge you to only use the concepts from chapters 1 and 2.) You may not use any programming constructs that are not in chapters 1 through 3 of the textbook.

You should continue to use static methods to structure your solution.  You should try to avoid significant redundancy and you should 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. This means try to minimize the number of class constants. You should only have one class constant, size, but you can have other variables declared locally in methods if you wish.

Complete the comment at the beginning of your Rocket.java program. Include a comment for each method you write explain 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 figure of a different size.  For example, with subfigures of height 7, the figure would look exactly like the larger rocket shown above.

When finished turn in your Rocket.java program using the turnin program.

Files
File Responsibility
Rocket.java (Provided shell) You and me. (Okay, mostly you.)
Checklist Did you remember to:
  • NOT FIDDLE WITH CODE WHEN TRYING TO GET IT TO WORK! Solve the problem on paper first and then code. If your solution doesn't work, DON'T FIDDLE WITH IT HOPING TO GET IT TO WORK. If your program doesn't work, print out the source code and simulate it by hand to understand the problem. Once you understand the problem, it will be a lot easier to fix.
  • review the general assignment requirements?
  • work on the assignment individually?
  • fill in the header in your file Rocket.java
  • create a logical, structured solution that is easy to understand and reduces redundancy?
  • ensure your program does not suffer a compile error or runtime error?
  • ensure your program has a class constant that when changed produces the appropriately sized figure?
  • Only use concepts and tools from chapters 1 - 3 of the textbook? (You are allowed, but not required, to use parameters.)
  • put a comment on each method describing in broad terms, what it does?
  • turn in your Java source code in a file named Rocket.java to the proper account in the Microlab via the turnin program before 11 pm, Thursday, September 18?

Thanks to Stuart Reges for letting me use this assignment.

Back to the CS 305j homepage.