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

Lab Assigned
Design Due
(In class)

10 AM
Implement
(In Lab)
Demo
(In Lab)
Lab Due
(In class)
Friday
10 AM
24 Jan None 25-26 Jan 1-2 Feb 04 Feb

Goals:

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

Before starting:

Read over the entire lab before you start. Before beginning the assignment, download the provided portions of the lab into your cs101 folder by clicking on the "download project" button in the on-line version of this assignment.
[[[download project folder for PC]]]

Assignment:

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 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 in four even steps, where in each step you:

  5. 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 in four even steps.

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 by 10:00am IN CLASS on the due date.  Check that you have filled in the 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 09:34:16 CST 24 January 2000 by Ron K. Cytron