Write a program that produces the following figure (which vaguely resembles the Seattle Space Needle) as its output. Use a class constant to make it possible to change the size of the figure (the following output uses a size of 4).
Program:
public class Ch02PP06
{
public final static int SIZE = 4;
public static void main(String[] args)
{
printNeedle();
printFirstHalf();
printSpacer();
printSecondHalf();
printNeedle();
printBody();
printFirstHalf();
printSpacer();
}
public static void printNeedle()
{
for (int i = 1; i <= SIZE; i++)
{
for (int j = 1; j <= 3 * SIZE; j++)
{
System.out.print(" ");
}
System.out.println("||");
}
}
public static void printFirstHalf()
{
for (int i = 1; i <= SIZE; i++)
{
for (int j = 1; j <= SIZE - i; j++)
{
System.out.print(" ");
}
System.out.print("__/");
for (int j = 1; j <= i - 1; j++)
{
System.out.print(":::");
}
System.out.print("||");
for (int j = 1; j <= i - 1; j++)
{
System.out.print(":::");
}
System.out.println("\\__");
}
}
public static void printSpacer()
{
System.out.print("|");
for (int i = 1; i <= SIZE; i++)
{
System.out.print("\"\"\"\"\"\"");
}
System.out.println("|");
}
public static void printSecondHalf()
{
for (int i = 1; i <= SIZE; i++)
{
for (int j = 1; j <= 2 * i - 2; j++)
{
System.out.print(" ");
}
System.out.print("\\_");
for (int j = 1; j <= 3 * SIZE - 2 * i + 1; j++)
{
System.out.print("/\\");
}
System.out.println("_/");
}
}
public static void printBody()
{
for (int i = 1; i <= SIZE * SIZE; i++)
{
for (int j = 1; j <= 3 * SIZE - 3; j++)
{
System.out.print(" ");
}
System.out.println("|%%||%%|");
}
}
}
Output: