Project #2 CMSC 131
Due:  Thursday 2/23 at 11:00PM Object-Oriented Programming I
Type of project: OPEN Spring 2006

Letter Maker



This project will give you some practice with loops, and introduces the notion of having multiple classes working together in a single project.



The project consists of several classes working together -- most of them are provided for you -- only one class (LetterMaker) will be written by you.  The final product will draw large letters made from blocks; the letters 'L', 'O', 'J', 'T', 'H', and 'X' will be drawn (scroll down for a while to see some examples.)

This project is considered "open". Please visit the course web page for information regarding the open/closed policy for projects of this course. 


Color Class

One of the classes  you will use for this project is provided in one of the available Java graphics packages.  It is the "Color" class, and it is part of a package called "java.awt".  That means that any class that wants to use Color objects must begin with the following statement at the top of the file:

 import java.awt.Color;

You do not have to actually create Color objects yourself (that is done for you in the code that is provided by us), but if you wanted to create your own Color object you could use a statement like the one below:

Color myColor = Color.BLACK;  // myColor now refers to the color "black"

There are other ways to generate just about any color you could imagine, but the simple syntax shown above works for the following built-in colors:  BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, YELLOW.


DrawingGrid Class

The DrawingGrid class has been written for you.  It is part of a package called "CMSC131GridTools".  That means that any class that wants to use DrawingGrid objects must begin with the following import statement at the top of the file:

import CMSC131GridTools.DrawingGrid;

A DrawingGrid object is a window that you can draw on.  In the center of the window there is a square grid.  You can color in each region of the grid with any color you want.  Below is an example of an "empty" 9 by 9 DrawingGrid object:


Creating a DrawingGrid Object

You don't actually have to create any DrawingGrids yourself for this project (they're created by code that has been provided for you), but if you wanted to create a new DrawingGrid object, you could use a statement like this one:

DrawingGrid myGrid = new DrawingGrid(13);  // myGrid will refer to a 13 by 13 drawing Grid


Coloring the Squares on the Grid

Once you have a DrawingGrid object, you can color in any of the squares you want using any color you want.  To do this, you use the method of the DrawingGrid class called setColor.  The setColor method of the DrawingGrid class takes three parameters.  The signature for the method appears below. 

public void setColor(int row, int col, Color color)

The parameters "row" and "col" specify the location of the square on the grid that you would like to color in; the parameter "color" refers to the color you want to use. Note that the first row is row number 0 (not row number 1), and the first column is column number 0.  For example, below is a picture of what you would see if you executed the code fragment that follows.

DrawingGrid myGrid = new DrawingGrid(5);  // creates the 5 by 5 DrawingGrid

myGrid.setColor(3, 3, Color.RED);      // colors in the square at row 3, col 3, using red

myGrid.setColor(0, 2, Color.BLUE);     // colors in the square at row 0, col 2, using blue

If a particular square on the grid has already been colored, there is no harm in re-coloring that same square -- the previous color will simply be replaced with the new color.


Determining the size of the DrawingGrid

There is one other method of the DrawingGrid class that you will need.  Suppose you have a variable called "myGrid" that refers to an existing DrawingGrid, and you want to know how big it is.  You can use the method "getScale" to find out.  The signature for this method appears below:

public int getScale()    // the return value is the size of the grid

For example, if the variable "myGrid" refers to an existing 17 by 17 DrawingGrid object, then the following expression would be equal to the integer 17:



LetterMaker Class

OK, this is where YOU come in!  We have provided a skeleton for this class that you must complete.  There is basically just one method that you must fill in, although it is okay for you to create other methods in this class if you find it useful to do so.  You may find that writing additional methods can help to eliminate duplicative code.  Since we will not be creating any LetterMaker objects, any methods you choose to write in this class should be declared using the keyword "static".

The method that you must write has the following signature:

public static void drawLetter(DrawingGrid grid, char letter, Color color)

Remember that the three parameters (grid, letter, and color) are provided to your method by whoever called it.  Those parameters contain the information that your method needs in order to do its job.

The parameter "grid" will refer to an existing DrawingGrid object that has already been created by someone else.  Your method should not create a DrawingGrid, it is already there!  Your method will draw on the grid that is passed in via this parameter.  You may assume that the grid starts off empty (all white squares).

The parameter "letter" will be equal to one of the following characters: 'L', 'O', 'J', 'T', 'H', or 'X'.

Using the Color specified by the parameter "color", your method will draw a big block-letter on the grid (see the section below for examples), depicting the letter specified by the "letter" parameter.  The style for this block letter must conform exactly to the examples below.  Note that the size of the grid can be determined by calling the "getScale" method of the DrawingGrid class.  The size of the grid dictates how big of a letter you are supposed to draw (the letter must fill up the entire grid, as in the examples shown below.)


Examples of Letters

What follows are examples of the style that you must use for drawing your letters.  We'll show two examples for each letter:  size 9 by 9 and size 17 by 17.  Note that the "brush-strokes" for the letters is always 3 squares wide.  Your letters must conform exactly to the styles below.  The letter must take up the entire DrawingGrid, no matter what size the grid is. Your drawLetter method must be capable of drawing letters of any size that is odd and at least 9.  (I.e. sizes 9, 11, 13, 15... are all valid sizes that your method should be able to handle.  There is no limit, so your drawLetter should work perfectly well for a DrawingGrid of size 999 by 999 or even larger!)  Reminder: the DrawingGrid is always square.

Here are examples of the letter 'L':

Here are examples of the letter 'O':

Here are examples of the letter 'J'.  Note that the "tail" on the left side always goes up to a row that is just one unit below the middle row.


Here are examples of the letter 'T':



Here are examples of the letter H:

Here are examples of the letter 'X'.  Pay particular attention to how the corners look!  This is the trickiest one.


Testing Your Work (the ExampleDriver Class)

Please note that the class you are writing does not include a "main" method.  The expectation is that your LetterMaker class will be used by some other class that does have a main method.  In other words, you are writing a module that can be plugged into a larger project.  To help you to test your class, we have included a class called "ExampleDriver" in the files you have been given.  This class does have a main method.  It provides a simple user interface that will allow you to experiment with the LetterMaker class that you are working on.  Please take a look at the code we have provided in this driver class -- you'll see that it asks the user what kind of letter he/she wants to see, then it creates it's own DrawingGrid and then calls the drawLetter method that you will be writing. Note that the letters that you enter to test your project using this driver should be UPPER CASE letters. 

Please note that the ExampleDriver class is not really part of the project assignment!  It is only provided to help you test out your code.  In fact, when we test your LetterMaker class ourselves, we will be using a completely different driver class.  Feel free to write your own driver class to test your LetterMaker class a different way, if you want to.


Getting Started

Begin the project by "checking out" the project called "Spring06Proj2".  In order to help you get started, we have included a LetterMaker class with a skeleton version of the "drawLetter" method, which you must complete.  Remember that you must have set up your repository in order to check out and submit projects.  Information on how to do this can be found in the Managing Homeworks section of the Eclipse tutorial. Follow the instructions given there to check out project Spring06Proj2. Then when you switch back to the Java perspective, you will see the above files in the "Package Explorer" window, and you will be able to start modifying them.

If you write the project from scratch, without checking out the "Spring06Proj2" files from your CVS repository, you will not be able to submit your work.





Submit your project from Eclipse by right-clicking the project folder and selecting "submit".  You may submit as many times as you want -- we we only grade the submission that scores the highest on the automated tests.  After you have submitted your project, you should visit the submit server.  There you can obtain limited feedback about how well your project is performing.  The number of times you can run our tests on your project (before the due date) is limited.  The earlier you begin working on the project, the more opportunities you will have to see how your project performs on our tests before the due date!



There will be one automated test for each type of letter, and they will be run in the following order:  'L', 'O', 'J', 'T', 'H', 'X'.  For that reason, it is strongly recommended that you write code to process the letters one-by-one in that order.  (Start with 'L', then once that is finished and working properly, then work on 'O', etc.)

Web Accessibility