Last Update: Oct. 24, 2025

Assignment 3 (PS3): Patterns, using Numbers, ASCII, and Pixels. Nested Loops

This assignment focuses on nested loops and methods with parameters, through drawing patterns.

Due: 11:55 PM, Tuesday, Oct. 28, 2025.

Lead TFs: TBA


Part 0: Draw X in ASCII.

Please watch this video on how to draw X of different sizes using for loops and methods.

Part 1: Number Coolness

If you search on the Internet "123456789 x 8 + 9 = 987654321", you will see posts on the coolness of numbers. One number pattern often quoted is the following:

        1 x 8 + 1 = 9 
       12 x 8 + 2 = 98 
      123 x 8 + 3 = 987 
     1234 x 8 + 4 = 9876 
    12345 x 8 + 5 = 98765 
   123456 x 8 + 6 = 987654 
  1234567 x 8 + 7 = 9876543 
 12345678 x 8 + 8 = 98765432 
123456789 x 8 + 9 = 987654321

In this part, you will generate the pattern by a computer. In particular, you will write a method named printNumberCoolness that should receive a single parameter, representing the number of rows that it should output (you may assume that this parameter is always a number between 1 and 9), and your program will print the number of rows of the pattern. For example, printNumberCoolness(9) would print the exact output above (formatted in the same way). But printNumberCoolness(5) would print only the first 5 lines, formatted like the below (note that the final line never has any spaces before it, and all the lines above it are adjusted accordingly):

    1 x 8 + 1 = 9 
   12 x 8 + 2 = 98 
  123 x 8 + 3 = 987 
 1234 x 8 + 4 = 9876 
12345 x 8 + 5 = 98765

One approach is to generate the pattern without actually doing the calculation. But you appreciate the beauty more if your program actually does the computation. Note that the first number of each line is equal to the first number of the previous line times 10, plus the line number. For example, the first number of the first line is 1. Therefore, the first number of the second line is 1*10 + 2 = 12. The first number of the third line is 12*10 + 3 = 123. The first number of the fourth line is 123*10 + 4 = 1234. Etc. You should construct and print this integer, and then multiply it by 8 and add the appropriate amount to print the last number of each line.

Style Guide and Implementation Suggestions

Use the following code to get started:

//*******************************************************************
//
//   File: NumberCoolness.java          Assignment No.: 3
//
//   Author:       Email: 
//
//   Class: NumberCoolness
// 
//   Time spent on this problem: 
//   --------------------
//      Please give a description about your design. 
//
//*******************************************************************
public class NumberCoolness 
{
  // main
  public static void main(String[] args) 
  {
    printNumberCoolness(3);
    printNumberCoolness(9);
  }

  public static void printSpaces(int nSpaces) 
  {
    for (int i = 1; i <= nSpaces; i++)
    {
      System.out.print(" ");
    }
  }

  // Your method here
}

Your solution is to add to the given code above. Once your method has been written, the output of the above program should be:

  1 x 8 + 1 = 9
 12 x 8 + 2 = 98
123 x 8 + 3 = 987
        1 x 8 + 1 = 9
       12 x 8 + 2 = 98
      123 x 8 + 3 = 987
     1234 x 8 + 4 = 9876
    12345 x 8 + 5 = 98765
   123456 x 8 + 6 = 987654
  1234567 x 8 + 7 = 9876543
 12345678 x 8 + 8 = 98765432
123456789 x 8 + 9 = 987654321

Part 2. Rocket Ship

In this part, you are going to generate outputs of ASCII rockets. The subfigures in a rocket have the property that their height determines their width, so there is only one scale variable. The various subfigures in the middle of example below have a height of 3. Thus, it is a rocket of scale 3.

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

A rocket of scale 5 has an output that should look like this:

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

Style Guide and Implementation Suggestions

As always, please include comments in DrawRocket.java.

//*******************************************************************
//
//   File: DrawRocket.java          Assignment No.: 3
//
//   Author: <your name>      Email: <your email>
//
//   Class: DrawRocket
// 
//   Time spent on this problem: 
//   --------------------
//      Please give a description about your design. 
//
//*******************************************************************

Part 3: Submit Your Assignment

Please submit electronically for assignment #3 and make sure you submit (1) NumberCoolness.java, and (2) DrawRocket.java. Please be sure that you choose the .java file, NOT the .class file when uploading. The .class file is the compiled version of your code which we cannot examine and grade. So, please make sure you submit *.java files. Also, remember that you always need to include the header.

//*******************************************************************
//
//   File: FileName.java          Assignment No.: 3
//
//   Author: <your name>      Email: <your email>
//
//   Class: ClassName
// 
//   Time spent on this problem: 
//   --------------------
//      Please give a description about your design. 
//
//*******************************************************************

The submission repository for ps3 is https://gitee.com/simmonsong/ct-xmuf25-ps3.

Please follow the instructions in Assignments Submission to submit your assignments.

Git introduction is a help document for git utilization..

Enjoy!


Some part of the problem set derived from Building Java Programs.