The following code is my solution of exercise 10 of chapter 5 of THE ART AND SCIENCE OF JAVA. So here, using acm program and graphics, i need to draw a castle with two side towers and other three consecutive towers some distance away from the main building(castle and its two side towers). Is there any way to do this faster than that? Thanks! (Code is tested and has no bugs, the drawing is perfect as i spent plenty of time searching for the perfect location for every object on the canvas).
import acm.program.*; import acm.graphics.*; public class Hw1 extends GraphicsProgram { final double tower_width = 150; final double tower_height = 600; final double main_house_width = 400; final double main_house_height = 500; final double s_tower_width = 75; final double s_tower_height = 300; final double door_width = 50; final double door_height = 100; final double window_width = 100; final double window_height = 100; GRect create_tower(double x, double y) { GRect rect = new GRect(tower_width, tower_height); rect.move(x, y); return rect; } GRect create_main_home(double x, double y) { GRect rect = new GRect(main_house_width, main_house_height); rect.move(x, y); return rect; } GRect create_s_tower(double x, double y) { GRect rect = new GRect(s_tower_width, s_tower_height); rect.move(x, y); return rect; } GRect create_door(double x, double y) { GRect rect = new GRect(door_width, door_height); rect.move(x, y); return rect; } GOval create_window(double x, double y) { GOval circle = new GOval(window_width, window_height); circle.move(x, y); return circle; } GPolygon create_arch(double x, double y) { GPolygon arch = new GPolygon(); arch.addVertex(x, y); arch.addVertex(x+150, y); arch.addVertex(x+75, y-150); return arch; } GPolygon create_s_arch(double x, double y) { GPolygon arch = new GPolygon(); arch.addVertex(x, y); arch.addVertex(x+75, y); arch.addVertex(x+37.5, y-100); return arch; } GPolygon create_arch_door(double x, double y) { GPolygon arch = new GPolygon(); arch.addVertex(x, y); arch.addVertex(x+50, y); arch.addVertex(x+25, y-50); return arch; } GPolygon create_house_arch(double x, double y) { GPolygon arch = new GPolygon(); arch.addVertex(x, y); arch.addVertex(x+400, y); arch.addVertex(x+200, y-200); return arch; } public void run() { add(create_tower(700, 250)); add(create_tower(150, 250)); add(create_main_home(300, 350)); add(create_s_tower(1000, 550)); add(create_s_tower(1200, 550)); add(create_s_tower(1400, 550)); add(create_door(475, 750)); add(create_window(350, 450)); add(create_window(550, 450)); add(create_arch(150, 250)); add(create_arch(700, 250)); add(create_s_arch(1000, 550)); add(create_s_arch(1200, 550)); add(create_s_arch(1400, 550)); add(create_arch_door(475, 750)); add(create_house_arch(300, 350)); } }