CS 101 - Intro to Computing, Spring 2010

Lab 3

Running DrJava in the CS Labs

To run DrJava in the CS Labs, you will first need to copy the bookClasses directory and set the classpath. There is a script (i.e. small operating system program) that will do this for you. From a terminal window, enter the following:

     ~i101/setupDrJava
Only enter the above command once.

After the bookClasses directory has been set up, enter the following command to start DrJava:

     ~i101/runDrJava
Once DrJava is up and running, it should work the same as it has on the ACCC's windows machine. Actually is should work better. At least, it will run faster.

Lab Assignment

Due: Thursday 2/4/2010 by 11:59 pm

For this lab assignment, complete the following:

  1. Using a single turtle, write out your initials on an image/world. Each letter needs to drawn in a different color. This lab is assuming your initials have 3 letters. If you don't have three letters for your initials, add a number to get it to at least three "initials".

    The key to this lab is to write the letters using very "blocky" upper case letters. For example:

    I made letters that were 100 pixels high and 50 pixels wide. I also put a space of 25 pixels between each letter and left a space of 25 pixels around the border. You don't need to follow my plan exactly, but I think it works fairly well. I also set the width of the pen to be a little thicker than the default size of 1 pixel wide. Remember to keep the pen up between letters. This is done by using the penUp() and penDown() methods of the Turtle class. Refer to the JavaDocs for the bookClasses page to more information.

    Also, remember to change the color of the pen. To use color, you will need to add an import statement at the top of you program. This statement will add in the Java Color class from the Java-AWT library:

    import java.awt.Color;
    AWT stands for the "Abstract Windowing Toolkit". You could import the entire AWT library if you wished without causing any undo harm to the program but it is not really needed in this case. To do this, you would replace the word "Color" with an asterisk "*".

    Once you have added the import statement, you specify the color of the pen using the setPenColor() method from the Turtle class. The parameter will be the color you wish to use. The parameter will be given as: Color.xxx where xxx is the name of the color you wish to use. Note: the color names need to be defined in the library first. To find the defined color names check out the Java Sun Web Page on Color. The values is listed in the "Field Summary" section.

    For example, set have the turtle "turtle1" draw with the color red you would use the code:

    turtle1.setPenColor ( Color.red );
    Also you can check out the code we did in class that draw shapes in different colors. That code is Lect128c.java .

  2. Be sure to include a comment at the top of your java file that contains the following:

  3. You are also to submit the Java file electronically via the following steps.

    How assignments should be submitted

    1. Go to the blackboard site for the class
    2. Select "Assignments" on the left bar
    3. Locate the correct assignment to submit; click on "View/Complete Assignment" at the bottom of that assignment
    4. Next to "Attach local file", click "Choose file", choose the file you want to submit; please submit only ONE file, properly named.
      For example for lab2, name it Lab2yournetid.java, for example if your Net ID is sfranz3, the filename would be Lab2sfranz3.java
      Please only submit source code file (the .java file, not the .class). Also, if you have any comment about your program, please write it down in the same file; please do NOT write in the "Comments" field on the submission page (this will go into a different file and will be easily missed).
    5. Hit "Submit"
    6. Go back once again to View/Complete assignment and make sure that your file was submitted; also, this page will show your grade and comments (if any) after assignments are graded.