CS 101 (Fall 2000)
Lab 1: Expressions, Functions, and Procedural Abstraction

Lab Assigned Design Due
(In class)

1 PM
(In Lab)
(In Lab)
Lab Due
(In class)
1 PM
11 Sep None 13-14 Sep 20-21 Sep 22 Sep


By the end of this lab, you should...

Before starting:

[[[download project folder for PC]]]


You're a city planner for St. Louis, which is looking to expand its borders to the surrounding acreage of Missouri. Your job, in this lab, is to be able to direct the building of St. Louis' expansion to your own ends.

You will implement a Skyline class that draws buildings on the screen and tells you some important planning information about these buildings. Think of this as a much-simplified version of playing architect; although the task seems simple enough (with one twist we'll reveal at the end), this is an example of computer-aided design; to build a building, just point and click!

  1. Begin by opening the Skyline.java file in Emacs. (When you choose "Open File..." from the Files menu, a message will appear at the bottom of the screen asking which file you wish to open. Please see a TA if you need assistance.)

    Supply the necessary header information (name, lab section, etc.). This is the only file you need to modify for this lab. Look over the file carefully before modifying it! Please note the following:

    Each of the following specifications describes the input parameters and return values of a desired procedure that is needed as a method of the Skyline simulator. For each specification,

    Hint: To avoid making the same mistakes over and over, test as you go. That is, type in a procedure, compile, execute, and verify the results, and then go on to the next problem.  After you get the hang of it, you can write more code before you test.  Detailed instructions for running your program are listed below.

  2. Write a method called drawBuilding that does the following: It is important to remember that in computer graphics, the y-coordinate increases going down the screen rather than going up. We have provided the named constant CANVAS_HEIGHT to represent the y-coordinate of the bottom of the screen. A diagrammatic representation of the building you should produce looks something like this:

          (x,y)   		    (x+width,y)
    	|			|
    	|			|
    	|			|
    	|			|
    	|			|
       (x,CANVAS_HEIGHT)	(x+width,CANVAS_HEIGHT)

    There are only three lines; you should leave the bottom line out (as if the building were to extend below the bottom of the canvas).

  3. Write a method called reportSquixels that: The method takes no parameters. (FYI, "squixels" is a term we made up to represent "square pixels". A pixel is a dot on the screen, essentially.) In order to do what is required, you will need to keep track of instance variables in your Skyline.java file; for example, you may want to have a variable which represents the total of all building areas, and update it anytime a building is drawn. Instance variables (also known as fields) will be covered in class.

  4. Write a method called makeArch that draws an arch in the middle of the skyline. To accomplish this, 2 Arcs will be drawn. The makeArch method takes in an integer Y-value. The first Arc will be placed at this y-coordinate. The x-coordinate must be calculated. To do this:

    The second Arc will be placed inside the first one to create the full arch. For this Arc:

    NOTE that Arcs are created in a U-shape. You must rotate it to get the proper result. Add them to the skyline and an arch is born!!

  5. Write a method called earthquake that causes the last building you drew on the skyline to collapse into the ground. It takes no parameters. Again, you will need instance variables in your class to "remember" the last building you drew. You can use the instance variables to represent the three lines that make up the building and the height of the building. Your earthquake method should make the building fall by using the smoothMove method within canvas. Call smoothMove(int newX, int newY, int milliseconds) on each of the three lines. The lines' x-coordinates DO NOT change, their new y-coordinates should be the CANVAS_HEIGHT, and the input value for milliseconds is how many milliseconds it will take to move the lines to the new position.

  6. Execute your program by opening Lab1.java (in the same folder as Skyline.java) and compiling it (choose "Compile" under the "JDE" menu). After the compile has finished successfully (you will see a message saying so), you may run the program by choosing "Run App" from the "JDE" menu.

    You should see an empty skyline. Click anywhere on the screen to place a building; the next building will be drawn starting from the left side of the screen and whose top is exactly aligned with the y-coordinate of where you clicked. Be sure that your program prints out the correct messages and that the earthquake happens smoothly.


What To Turn In:

For every CS101 lab you turn in, you should fill in a cover sheet and staple it on the front of your lab. Attach a paper printout of the following:

  1. your Skyline.java file containing the methods you wrote, and
  2. your transcript.txt file created when you ran your program. This must be turned in by the start of class on the due date.  Check that you have header information (name, email, date, and lab section) at the top of the file, and be sure to demonstrate the lab for a TA before turning it in!

If you need help printing, ask a TA or refer to the lab homepage, which has detailed instructions for how to print from the labs.

Last modified 12:26:13 CDT 12 September 2000 by Ron K. Cytron