Skip Site NavigationCarleton College: Home
 
 

This is a team assignment.

Many complicated movie scenes that you see involve lots of individually generated objects, all assembled together on one screen. A computer generated movie scene of a city (such as in Spiderman) involves superimposing a number of buildings of different shapes and sizes. For this assignment, you will create a city by drawing a number of buildings of varied sizes.

Create a directory named skyline to store your work, then copy into it the Canvas class from the course directory. (For part 2, copy your directory and all code within to another directory called skyline2; that way, you don't clobber your first submission when you turn it in.) Create a class called Building to represent a building in a city. Specifically, it should have the following methods:

Part 1


  • a constructor

  • public void setHeight(int h)
    (sets the height of the building to h)

  • public void setWidth(int w)
    (sets the width of the building to w)

  • public void setColor(Color col)
    (sets the color of the building to col)

  • public void setHorizontalLocation(int loc)
    (sets how many pixels over from the left of the canvas the building begins)

  • public void draw(Canvas canvas, int canvasHeight)
    (given a canvas and its height, draw the building. The reason that you need the the height of the canvas to figure out where to start drawing the top of the building. If buildings extended down from the top of the canvas, i.e. the picture were upside down, this wouldn't be necessary.)

Part 2


  • public void setHeightRandom(int maxHeight)
    (sets the height to a random value from 0 to maxHeight, inclusive)

  • public void setWidthRandom(int maxWidth)
    (sets the height to a random value from 0 to maxWidth, inclusive)

  • public void setLocationRandom(int maxLoc)
    (sets the horizontal location to a random value from 0 to maxLoc, inclusive)

  • public void setColorRandom()
    (sets the building color randomly)

  • public int area()
    (returns the area of the building (width * height). This is used for determining real-estate taxes.)

You should add on your own any private instance variables that you need.

Draw your building by doing what you can to make a rectangle look building-like. Add an antenna to the top of the building whose height is proportional to the rest of the building. Draw windows running down and across the buildings. You don't need to crazy making the width of the windows correct or anything like that: some attempt at making some kind of repeated pattern of windows should do the trick. Of course, feel free to get as fancy as you like after you get everything else working.

Test your code as you go along. In other words, create another class called Skyline that creates and draws some buildings. As you write methods in Building, test them in Skyline.

When you are all done with Part 2, test your code against the Skyline.java that I provide. If you have built your Building class correctly, this Skyline program should generate an awesome skyline for you to look at.

Good luck, and have fun! Remember that lab assistants and prefects are available to help out if you need it.

Available from: Tuesday, April 17 2007, 04:45 PM
Due date: Friday, April 20 2007, 11:55 PM