[CS111 Home Page]
[Syllabus]
[Students]
[Lecture Notes]
[Assignments]
[Programs]
[Documentation]
[Software Installation]
[FAQ]
[CS Dept.]
[CWIS]
CS111 Laboratory assignment 3: Naming Variables
Due Date: 6:00 p.m., Thursday, September 25.
Naming Different types of Variables (In Class)
In lecture on Thursday, you learned how to replace
integer values with named integer variables, in the
"House" example. Today we will review that naming
and discuss how to name floating point numbers,
Polygons, Colors and Fonts.
You can review the material discussed in lab by looking
at the
Polygon contract,
Color contract, and
Font contract.
Using named variables in a java program (To be handed in)
Now you will get some practice naming variables. To start
with, download the folder named "person_project" in the CS111
download folder. This folder contains four files:
- person.proj
- person.java
- person.html
- person.class
Open the project by double-clicking on the person.proj file.
Now bring the project up to date, and view the applet with
the applet viewer. You should see a person:
This person is specified by a bounding rectangle, whose
lower left-hand corner is at (x,y) position (50, 160), and whose
height is 120 pixels and whose width is 90 pixels. The
proportions of each of the body parts is specified in the
following diagram (Note that the head width is 1/3 the total
width, and its height is 1/4 the total height):
Your task:
Replace all of the numbered coordinates with coordinates
that depend only on x,y, width and height of the bounding
rectangle (you will need to name these variables)
and the proportions given above. Also name
the head color, dress color, and line color. Place the
left end of the baseline for the text at the left edge of
the person's rectangle, and 30 pixels below the bottom
edge of that rectangle. When you are finished,
you should be able to change
only the 4 variables ( x and y for the lower left corner,
width and height) and have the
entire picture change in proper proportion.
Turning in your assignment:
When you are finished, upload the folder "person_project"
containing the four files (person.proj, person.java, person.html,
and person.class, with the changes you made to them for this
assignment) into your subdirectory of the lab3 drop
folder in the cs111 directory.