CSC274b
Spring 1998
Ileana Streinu
Programming Assignment 1
Friday, Feb. 20, 1998
Due: Friday, Feb. 27, 1998
The purpose of this assignment is to:
- Give you a chance to explore how geometric concepts (points, polygons) are
represented as data structures in a real programming language.
- Allow you to explore a different type of assignment: writing
Java code. If you like it, we may do it more often.
The model and the sources:
- The applet
for the "beginners" assignment (to be used as a model).
- The
source code for
both assignments.
I did not get to do the
"advanced" assignment
myself, but if I have time to work on it
I will post it here in a few days, so that you see
how it should work.
Description
I am providing you with a Java interface to the algorithms that you will be
implementing. My programs have comments in those places
where you will have to insert your own code (such as, code
for computing the area of a
triangle or a polygon).
To start with, look at how the
applet
works right now: it is not
computing anything useful! Play with it for a while, to become
familiar with the desired functionality.
Report to me anything that does not seem to be working
properly: this is experimental code, alpha version, probably
still full of bugs despite my best efforts!
The parts that you will deal with are under the menu options Draw
and Compute. Click on the menu options, to see what it's doing
now. Open the Java console (from Netscape/Options) to see some
messages printed as various parts of the code get executed
(mainly from those parts of the code that you'll have to provide).
Your assignment is to insert code for
drawing a triangle (beginners) or a polygon (advanced), and for
computing the respective areas.
Java Source Code for this assignment is
here.
Take a look.
Quite a lot, isn't it? Don't panic! I put each class in a
separate Java file. It makes it easier to expand and maintain the
project. You'll have to copy all the Java files just once. For
the subsequent programming projects (if any!), you will reuse them.
Here's how to proceed to get the files into your class account:
- Go into your class account on grendel/hermite, 274b-xx.
- Go into public_html directory.
- Create there a directory named Program1. Make it accessible
with
chmod go+rx Program1
- Go into Program1 directory.
- Copy all the Java files from my directory in this
directory. The simplest way to do it would be this. Make sure you
are in the grendel (not hermite) class account and in the
directory Program1. Then do:
cp ~274b/public_html/Program1/*.java .
There is a space after cp, and a space before the final dot, but
I do not know how to make this show nicely in HTML :-(
- If this doesn't work, let me know. Another solution is to
save the files from within Netscape, then ftp them on grendel -
but it's quite tedious!!
- Similarly, copy the html file. Do not copy the class files -
you will compile them again anyway.
- Make sure the permissions of all the java files that you will
work on (this is explained a bit later) are all OFF, otherwise
anybody can look into your code. I will ask you to turn them ON
at the deadline (so that I can see what you have done!).
Once you've done this, your assignment is to go over the code,
spotting the parts marked with comments such as: 274 students,
insert code here. There are also other parts which I have marked
with 274 comments - but those are just to signal to you what is the
part of this program that is specific to this assignment. If you
choose to do a Java project later, you might have to modify or
expand those portions of the code (e.g. inserting more menu
options, handling those menu options, etc.)
After you modify the code, compile it with:
javac *.java
(again, there is a space after javac....)
then view it by going to the mApplet.html page in your
directory from Netscape.
Careful: before viewing, make sure all the class files are
readable. You can make them readable with:
chmod go+r *.class
And now, specific instructions for the beginners and for the advanced
Java students.
For Java beginners
Your task is to understand the code in the file myTriangle.java
and to fill in the formula for the part that is required. The
formula for computing the area is in your textbook. You also have
to compute the sign of the triangle. The interface automatically
will draw a positively oriented triangle in red, and a negatively
oriented on in green.
It is REALLY simple, in terms of coding - the major effort
is in understanding how the various pieces fit together and to
become familiar with the Java programming style.
For advanced Java programmers
Your task is to do first what the beginners do. Then you have to
understand the code in the file myPolygon.java
and to fill in the code for the part that is required: computing
the area of the polygon.
The
formula for computing the area is in your textbook and can be
easily implemented with a for loop. You also have
to compute the sign of the area. The interface will NOT
automatically
will draw a filled polygon, or display the results:
you will have
to implement the Draw and Display methods in the myPolygon class
for doing this.
Draw a polygon with positive area in red, and one with negative
arae in green, as in the triangle case.
What and How to submit
When done, transfer all the files (java, html and class) in a
directory named Prog1 in the public_html directory of your class
account 274b-xx. Turn the permissions on to html and class files
when done. For the source (java) files,
do so only before the class starts, on
Friday Feb. 27, 1998.
Do not hesitate to contact me if you have questions. Do not spend
hours debugging - if it seems hopeless, contact me (by
email). See me during office hours next week for assistance, too.
Ileana Streinu
Last modified February 20, 1998.