// This class extends the Science of Computing robots with the ability // to draw multi-tile lines. In addition to the features they inherit // from regular robots, these robots provide the following to clients: // // o drawLine, a message that takes an integer, n, and a color, as // parameters, and draws a line n tiles long in that color. This // message has no explicit return value. // Preconditions: The n tiles in front of the robot are unobstructed. // Postconditions: The robot is standing one tile past the end of // the line, facing in its original direction. // History: // September 2004 -- Created by Doug Baldwin. import geneseo.cs.sc.*; import java.awt.Color; class LineRobot extends Robot { public LineRobot( int c, int r, int direction, RobotRoom room ) { super( c, r, direction, room ); } // The "drawLine" method. public void drawLine( int n, Color c ) { for ( int i = 0; i < n; i++ ) { this.paint( c ); this.move(); } } // A "main" method that exercises the line-drawing method. public static void main( String[] args ) { RobotRoom room = new RobotRoom( "25 25" ); LineRobot r = new LineRobot( 3, 23, Robot.NORTH, room ); long startTime = System.currentTimeMillis(); r.drawLine( 12, Color.blue ); long endTime = System.currentTimeMillis(); long executionTime = endTime - startTime; System.out.println( "Drawing time = " + executionTime/1000.0 + " seconds" ); } }