Spring 1998
Ileana Streinu

Programming Assignment 1

Friday, Feb. 20, 1998
Due: Friday, Feb. 27, 1998

The purpose of this assignment is to:
The model and the sources:
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.


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:

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 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 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.