CMSC109 (Introduction to Computing)

Fall 2022

Assignment#5

Due before start of class on Monday, November 21, 2022.
[Extra Credit for Submission by start of class on Wednesday, November 16, 2022]

First, read OOP Notes.

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 class 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.

Once done: A program that uses your street light to draw a street scene is posted HERE. Create a new Sketch and save the program provided as the main part of the sketch. Then, make a copy of your StreetLight class and place it in this sketch. This way, the program will be able to use your StreetLight class. You do not need to modify the program provided.

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.

Hand in a printed write up (from (2) above in class as your submission.

Back to CMSC109 Course Web Page