|
The semester I took this class (Fall 2005), a new textbook was being used. Becker's Robots, Learning to Program with Java. The instructors were excited about this brand new book and the way in which it introduced object oriented concepts and ideas to students. I have to admit, I was slightly skeptical of using 'robots' to program. The robot takes the form of a triangular shape on the screen and moves around a 'city' which can be made up of things and walls. I was not to be disappointed, the book did prove to contain clear examples on many topics related to the robot idea. While there are certainly areas in the book that will need further development as the textbook is updated, in overall the book provided well thought out examples, and clear, easy-to-read text. For programming project two in this course, we were asked to design our own type of robot using inheritance from either the main Robot or RobotSE classes. An extra credit portion included creating a derivation of the City object. In classic style, since we hadn't seen a Hello World application as of yet, something I am eternally greatful to Becker for excluding from the first chapter, I created a Hello World application that printed the words in the proper Braille configuration. The BrailleBot lived in a BrailleCity, which used Walls to visually separate each letter.
The original source code and compiled class files are available below in the Files/Download section. They are provided as an example of a working program. It can easily be seen that parts could be improved. Keep in mind, this program was written before the programming project dealing with stepwise refinement. BrailleBot ImprovedRecently, I have written a BrailleBot class that is much more geared toward writing any number of letters in Braille. The bot has methods for printing every letter A-Z and the punctuation items: period, question mark and exclamation point. I chose to write the class in such a way as to be easily read and understood. Wherever a 'thing' is placed, it indicates a raised dot in Braille. There are perhaps, better ways to see the different dot configurations. One of these methods lends itself to a bit of stepwise refinement. For instance, consider the following Braille cell representation (a cell in Braille is a single character, that can be, but does not have to be limited to A-Z and punctuation). The numbers that correspond to each of the six dots are also shown.
Notice how there are two columns of three dots each. In Braille, a dot is either present or absent. Using knowledge gained from Discrete Mathematics, or by simply writing all combinations down, it is possible to see there are only eight different configurations in either column. Programming each as a helper method, and then combining those different items would be an alternative way to write the class. Certainly, the number of lines of code would be reduced. Would that reduction be worth losing part of the readability of the current setup? BraillerBotBraillerBot is a subclass of BrailleBot. It contains a method that will print an entire string. The default behavior for this class is to assume that each cell is directly adjacent from the next. Dots are printed in the order: 1, 2, 3, 6, 5, 4, as that is more efficient for the robot. So, by default, from dot 4 the bot moves to dot 1. If, as in the sample BrailleCity, there are walls, or you maybe want a blank column between cells, override the moveToNextCell method in your own subclass. Other IdeasI've already talked about a BrailleBot, BraillerBot, and a BrailleCity. If you notice in my BrailleCity, there are walls between each cell, those walls were hard coded in the program. Perhaps creating a subclass of Wall, BrailleWall, could be used to reduce code. For instance, pass in the upper left corner of the Braille cell, and have it build a border of walls in some configuration. I'll leave this as a programming project for some ambitious new programmer, or an instructor who wants to use it as an exercise or example. Files/Download
WebsitesJava: Learning to Program with Robots: www.learningwithrobots.com Sun Microsystems Java: www.java.sun.com Author ContactPlease direct any questions, comments, thoughts, suggestions or corrections to the author at Jake@JBrownell.com DisclaimerAll trademarks, product names, etc. mentioned in this document are held by Byron Webber Becker, his affiliates, Sun Microsystems or their specific creator. No claim is made to any of them. Copyright 2006 J. A. Brownell Last Updated July 24, 2006 |