Letter Maker

Objective

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

Overview

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 'C', 'U', 'H', 'O', 'I', 'N', and 'Z' will be drawn (scroll down for a while to see some examples.)


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" 11 by 9 DrawingGrid object:

empty11.jpg

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 only method that is provided colors in exactly one square of the grid – no more. 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

twoDots.jpg

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 "getGridSize" to find out. The signature for this method appears below:

public int getGridSize() // 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:

myGrid.getGridSize()

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. It is recommended that you 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, String letter, Color color)

Remember that the three parameters (grid, letter, and color) are provided to your method by the method that calls 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 the driver that calls this method. Your method must not create a DrawingGrid, it is already there and if you create another it won't display or test correctly! Your method will color squares 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: "C", "U", "H", "O", "I", "N", "Z" or "error". The "error" indicates that the user did not type in a valid letter. This should display as dot in the bottom right corner as shown below.

The parameter "color" will indicate the color the user has selected or black if the user did not indicate a valid color option.

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 "getGridSize" 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.)

is this a good method,
public static void main (agrs[]);

...If you haven't ever touched a Java program, shouldn't you be starting with HelloWorld.java?

...If you haven't ever touched a Java program, shouldn't you be starting with HelloWorld.java?

Don't be silly! Everyone knows you should start straight with a big multitier enterprise application if you have no experience whatsoever!

After reading the post, I realized, that everything has been given to you with plenty of explanation and you had to write only one method.
The method signature has also been given as well what you must do, what classes to use, what those do and how to use them.
I don't understand what more we can do apart from writing the code for you, which we won't, Because:
1) That is not what we do here.
2) You haven't provided any useful information, so we can give you some hints.

rofl I wish someone outlined methods for me like that on my assignments it would make life so much easier :D

This article has been dead for over six months. Start a new discussion instead.