/* Second version of a Java program (taken from pages 41-42 of Reges & Stepp ** (4th ed.)) that draws text figures (a diamond, an X, and a rocket ship). ** This (second) version improves upon the previous one by "capturing the ** structure" of the task the program carries out. (The fact that each of ** "draw a diamond", "draw an X", and draw a rocketship is a sub-task of the ** task to be carried out by the program is reflected by the presence of the ** methods that perform each of those sub-tasks.) ** However, like its predecessor, this version fails to eliminate redundancy. */ public class DrawFigures2 { /* Draws a few figures: diamond-shaped, X-shaped, and rocket-shaped. */ public static void main(String[] args) { drawDiamond(); System.out.println(); drawX(); System.out.println(); drawRocket(); } /* Draws a diamond-shaped figure. */ public static void drawDiamond() { System.out.println(" /\\"); System.out.println(" / \\"); System.out.println(" / \\"); System.out.println(" \\ /"); System.out.println(" \\ /"); System.out.println(" \\/"); } /* Draws an X-shaped figure. */ public static void drawX() { System.out.println(" \\ /"); System.out.println(" \\ /"); System.out.println(" \\/"); System.out.println(" /\\"); System.out.println(" / \\"); System.out.println(" / \\"); } /* Draws a rocket-shaped figure. */ public static void drawRocket() { System.out.println(" /\\"); System.out.println(" / \\"); System.out.println(" / \\"); System.out.println("+------+"); System.out.println("| |"); System.out.println("| |"); System.out.println("+------+"); System.out.println("|United|"); System.out.println("|States|"); System.out.println("+------+"); System.out.println("| |"); System.out.println("| |"); System.out.println("+------+"); System.out.println(" /\\"); System.out.println(" / \\"); System.out.println(" / \\"); } }