Homework #7 CMSC 131
Due April 20, 6:00 pm Object-Oriented Programming I
Type of Homework: Closed Spring 2005

Objective

This homework will give you practice in manipulating two-dimensional arrays, and designing programs that use the MVC (Model-View-Controller) design pattern for interaction.

Overview

For this homework you will implement the data (or model) part of the MVC design pattern for a program that implements a marquee. A marquee is a display unit as seen in old theaters and sports arenas, where a message is formed from a series of blinking lights. By varying the arrangement of lights over time, the marquee can produce the effect that the text is being scrolled from bottom to top across the window. Your task in this homework will be to implement this type of marquee. More details about the program are provided in the Specifications section. You may want to take a look at the Sample Run section before you read the description.

This homework will be graded as follows:

Specifications

You will write a program that lets a user display a message in a marquee. The marquee display consists of a 2-dimensional array of cells where each cell can assume the colors red or white (see the Sample Run section). The program will prompt the user for a message to display, and will process that message so it can be moved across the display from top to bottom. For this homework we are providing the view and controller part of the MVC architecture, and you must implement the model part. In other words, we will do the displaying, but you need to implement what is to be displayed at each step of the animation.

Animations

In order to understand what you must implement, let's first overview how we can create animations. An animation consists of a sequence of still images, which are rapidly updated, and so creates the illusion of motion. The redrawing process is triggered by a timer event, which fires regularly at some small time interval (e.g., every 10th of a second).

How does the Marquee program work?

For this homework we have implemented two classes named MarqueeDisplay.java and MarqueeController.java. These classes implement the view and controller part of the MVC architecture respectively. The MarqueeDisplay class has a method named displayMessage(), which takes a two-dimensional array of cells and displays the array on the marquee display. The MarqueeController class implements a timer that calls the displayMessage() method of the MarqueeDisplay class, with a particular two-dimensional array of cells, at a particular rate.

Where does the array that is being displayed come from? This is the result of calling a method named step(), which is defined in the class MarqueeDataManager. The MarqueeController class calls step() to obtain the next two-dimensional array to display. Each call produces a new 2-dimensional array, which has been shifted slightly relative to the prior one. This creates the illusion of motion. Your assignment is to implement the MarqueeDataManager class, in which you will define the step() method. You do not need to modify the MarqueeDisplay or the MarqueeController class. If you define step() correctly, the support classes will take care of the rest.

Code Distribution

Before you read these specifications, you should access the files associated with this homework by checking out the project named p7. The code distribution provides you with the following:

Here is a description of each of these components.

Marquee Library

The cmsc131MarqueeLib has the support classes you need for this homework. The classes you will find in this package are:

Java File

Your Assignment

Your assignment is to implement the MarqueeDataManager class. (Everything else is provided.) This class implements the DataManager interface therefore it must define the step() method. The step() method will return the next 2-dimensional array of Cell objects to display in the animation process. The MarqueeDataManager class must define a constructor with the following prototype:

The message parameter represents the message you want to display. The animationPattern is an integer that represents the animation pattern in which you are interested. We use 1 (one) as the animation pattern for this homework. You may assume the message contains valid (non-numeric) alphabetic characters; no extra error checking is necessary. Students implementing the challenge problem will use this value to distinguish between the animation pattern for the homework and animation patterns of the challenge problem. Your constructor should set up the state of the MarqueeDataManager object so that every time the step() method is called, a 2-dimensional array of Cells representing the next stage in your animation is returned.

Note: Your MarqueeDataManager class should define additional methods beyond step() and the constructor. This is part of your design. Feel free to add any method(s) you understand to be necessary and, if need be, any other classes that support your implementation. Incidentally, a method that appends two 2-dimensional arrays of Cell objects could prove extremely useful.

MarqueeDataManager step() Method Restrictions

The following restrictions must be observed as you implement the step() method:

Hints on Implementing the Marquee

You may follow any approach (algorithm) you deem appropriate for implementing the MarqueeDataManager class. The approach that we used in our implementation is based on a "sliding window" principle. Here is a general outline of the approach and a diagram.

The above procedure can be summarized as follows:

  1. Create a 2-dimensional array of cells whose number of rows is three times the height of the marquee's height.
  2. The first and last third of the 2-dimensional array rows should be initialized with empty ("blank") rows.
  3. The message to be displayed will be placed in the middle section of the 2-dimensional array. This message is     created  by padding the side(s) of the message to display.  The top and bottom of the message will be padded with empty ("blank") rows.  The left and right side will be padded with enough empty ("blank") columns so the message is centered on the display.  Keep in mind that the height of the actual message (non-padded) is less than the marquee's height (See ConfigValues).
    
     The so-called window is a subarray of the array created in step1,2, and 3.  The height and width of this window correspond to the height and width of the display.  Each call to step() returns the current subarray associated with the window and causes the window to slide down. Once the last row of the window reaches the last row of the padded-message array the window will wrap to the beginning of the padded-array.

Assumptions

    You can assume that the values provided in ConfigValues are correct.  That means, you don't have to worry about a character height that doesn't fit in the display height provided.

Requirements

Sample Run

Here is an example that shows some snapshots of the marquee as it displays the message "Go Terps". By the way in order to stop the marquee just close the display window.



Challenge Problem

Remember that you are not required to implement the following problem. Please visit the course web page for information regarding challenge problems. IMPORTANT: If you decide to complete the challenge problem you must provide its implementation in the file called Challenge.java.   Also make sure that your Challenge class has a default constructor.

Make sure that you provide a main method in the Challenge class that allow us to run your challenge problem. The main method is identical to the main method of the Marquee.java class, except that the animationPattern number will be two instead of one.

Challenge (3 Gold Stars)

Implement an animation pattern where your message moves from right to left wrapping around in the process.


Submission

Submit your project using the submit project option associated with Eclipse. Remember to complete your time log before submitting your homework.


Web Accessibility