Lab Assignment 3

CSC 220

Posted: February 14, 2005
Due: February 24, 2005

DO NOT IMMEDIATELY ATTEMPT TO PRINT THIS OUT. YOU WILL SWAMP THE PRINTERS AND WASTE PRECIOUS LAB TIME. YOU MAY OPEN MORE THAN ONE WINDOW! KEEP THIS PAGE OPEN WHILE YOU WORK.


Introduction

This lab is intended to give you practice reading code that others have written, including debugging that code. You should do this lab with a partner. Individuals who wish to work alone must get permission from their instructor. Only a single group of three will be allowed in any section of the course. Collaborate with some one in your section only.

Objectives of the Lab:

This lab illustrates This lab gives you practice in the following:

Background:

Creating sophisticated graphics from scratch in any programming language requires a complex program. Java object classes help to control the complexity of the task by doing much of the work for you. For this lab you will be introduced to the barest of fundamentals so that you can begin to draw graphics. The intent is not merely to introduce you to some fun programming, but to give you practice in the valuable skills listed above.

Chapter 3 of Koffman and Wolz provides an introduction to the concepts in this lab. In order to focus on graphics, we will use applets rather than applications for this lab. Recall that you run an applet with the appletviewer rather than with the java interpreter.  The .html file is the argument for the appletviewer. You may also run applets from a browser by visiting the .html page that contains the applet. More "hints" and help on html are provided in the Hints section below.


The Task: ( there are 5 steps to this lab)

Some of the steps below contain specific tasks for each partner in a pair. Assign partner 1 and 2 at the start and stick to the assignment. Check each other's work.  Groups of three: attempt to distribute the work evenly. Each member should participate in each step.

All files and directories referenced here can be found in ~mmmartin/www/Lab3/.

  1. Together: Copy the files from ~mmmartin/www/Lab3/ to a working directory in your account. The command is :  $ cp -r ~mmmartin/www/Lab3/* ~/www/lab3 . Compile and run the applet Squares from ~mmmartin/www/Lab3/Squares. Then examine the Java code where you will find comments that ask questions. Edit the code to respond to the question. Do not delete the question, but add new text to the comment that contains it. 
  2. Make another copy of the ~mmmartin/www/Lab3/Squares files in another working directory. The command are : $ mkdir ~/www/lab3/bkup                                                                      

     $ cp -r ~mmmartin/www/Lab3/* ~/www/lab3/bkup                                 
 

      3. Partner 1: Modify the code so that the two squares are centered at the point 100,100. The inner red box should have height and width of 50 pixels, the black square should have height and width of 70 pixels. Name the file Squares1.java. You will have to create an .html file (Squares1.html) to view it.

          Partner 2: Adapt the code from partner 1 so that the center point and the sizes of the squares are all declared as datafields. (e.g. the draw methods will refer to datafields rather than to literals such as 50 and 100.) Use datafields and local variables judiciously. Call this one Squares.java. You will be able to use the original html file (Squares.html) to view it.

          Together: Write two more versions of the applet: one that shows squares of size 100 and 200 with their center at location 100, 100; the second one that shows squares half as big at location 50,50. Name your applets Squares2 and Squares3. Use the html file ManySquares to display all three applets at the same time!

      4. Together: The file Castle.java from ~/lab3/Castles directory has both syntactic and run time bugs. Fix them. The proper solution can be found in the file ~mmmartin/Lab3/Castles/GoodCastles.class. The .java file (GoodCastle.java) is not provided for obvious reasons.

      5. Together: An embroidery sampler is a pretty picture that illustrates mastery of embroidery technique. Create a sampler to illustrate your mastery of the draw methods. Include as many of the draw methods as possible from chapter 3. Be creative! Have fun! You are to write a single applet that combines methods written by each of you. Use the software development method to define your task (the picture you want to create), analyze and design the solution, and then divide up the methods that you implement. Note that between you, you are writing a single class that extends applet.


Requirements:

Each partner should do his/her assigned task. If a partner gets stuck the other may help out, but under no circumstances should one partner do "all or most of the programming."

Create a web page that points toward each of your solutions. On each solution page include the applet as well as the source code. Do not place the applets for each task on a single page, link separate pages via an organizational page that identifies the programmers, the lab, the course etc.. Each "task" page should include a summary of the task, with full identification.

Submit a paper lab report during your class meeting on the due date. Submit only one report per partnership. The lab report should be produced on a word processor. Staple the completed report in the upper left corner. Do not use a report cover. The lab report should include in order:

Hints and Other Advice:

You can begin this lab without extensive knowledge of the AWT graphics functions. We will review these in class on Friday, September 24, but you will need to read Chapter 4 carefully to complete step 5.

ASK!!!!!!! your professor questions, in class, in lab, during office hours and especially via email. Please do not phone.

Don't know how to create a web site at TCNJ? Check out the following page: http://www.tcnj.edu/~im/tsnet/tsnet.html. Note that all files that are to be accessed by the outside world must have their protection value set to 755. Compiled class files ( *.class) do not get this value from the compiler. You must set it by hand. Make sure you are in the folder that contains the .class files and type: chmod 755 *.class (note that your folder must be within your /www/ folder for outsiders to access the applets from the web. Separate pages give information on html and file protections . Enjoy!

You may get help from classmates, tutors and other students outside your team on system technicals, syntax bugs, and small issues related to the Java language. Get help from anyone you can on how to print in the labs, how to move files from Mac to PC to Unix and back, how to add code to a word processing file, how to transfer a Word document written on a Mac to a PC and back.

You may NOT get help from the above groups to develop the solution to a task, to debug the code in task 3, or to implement your solutions in the other tasks. Other than your partner, no one may help you write, or debug your code except for times when you "simply cannot see what is wrong". If you cannot complete a task see your professor during lab, during office hours or send email.

The due date is considered the "last possible" moment to submit a report. You should be able to complete this project in a week if you distribute the work evenly between lab partners. A "down" system on the morning the lab is due will not cause an extension of the due date. Other universal calamities may be negotiated with the entire class. The point: hand SOMETHING of worth (e.g. the first few steps) in by the due date.