CMSC110 (Introduction to Computing)

Fall 2019

Assignment#4

Due before start of class on Thursday, October 31, 2019

First, read Chapters 8 & 9, from your text.

Task: Design a street light. You can design it anyway you like. You will model the street light using an object class as follows:

________________________________________________________________________________________
StreetLight
----------- Attributes:
x, y // location of bottom of light post
h // height of light post
on // is the street light ON? Constructor(s):
StreetLight(x, y, h) // Create a new street light at x, y of height h Behaviors:
display() // draws the street light (ON or OFF)
isON() // Return true is light is ON, false otherwise
turnOn() // Turns the light ON
turnOff() // Turns the light OFF _______________________________________________________________________________________


The design above, when implemented, can be used as shown below:

StreetLight light1, light2, light3;

void setup() {
	size(_, _);
  smooth();
  light1 = new StreetLight(x, y, h);	// Creates a street light at <x, y> of height, h
  light2 = new StreetLight(...);
  light3 = new StreetLight(...);

} // end of setup


void draw() {
	background(255);
  
  // turn the light on or off
  light1.turnOn();
  light3.turnOff();
	...


} // end of draw


The StreetLight class, as designed above, can be implemented using the template below:

class StreetLight {
  // Attributes
... // Constructor
void StreetLight(...) { ... } // StreetLight() Constructor // Behaviors...
boolean isOn(...) { // Returns true if light is "ON", false otherwise ... } // turnOn() void turnOn(...) { // Turns the light "ON" ... } // turnOn()

void turnOff(...) { // Turns the light "OFF" ... } // turnOn()

void display() { // Draws the street light (ON or OFF)
...
} // display() ... }// end of class StreetLight

The focus should be on the use of classes to define the Streetlight object factory. You will need to write the constructor, various operations for turning a given light on or off, drawing it, etc. When turned on, the display of the street light should visibly change.

A program that uses your street light to draw a street scene is posted HERE.

In your overall sketch pay special attention to the aesthetic aspects of your design.

What to Hand in: Hand in the entire sketch folder in your Dropbox folder. In addition to the sketch/programs also include; (1) a gif/jpg/png image of your finished sketch. (2) A formatted write-up (uisng the Assigmment Template) with Page#1 showing your sketch, followed by a title, your name, a short 1-2 line description (as discussed in class) on page#1, and a short 1-2 paragraph more detailed description of the sketch and your personal experiences working on this sketch. No printouts are necessary.

Back to CMSC110 Course Web Page