Homework Assignments.


Last updated on September 15, 2008.



Install the BlueJ IDE

Class Web Page

Subscribe to the SafariU Online Bookshelf

Reverse

Hello World Applet

Simple Draw Applet with a Circle

Simple Draw Applet with a Shape Factory

ArrayList Queue Implementation and Timing

Linked List Queue Implementation and Timing


  1. August 20: Install the BlueJ IDE
    1. Download the BlueJ Integrated Development Environment (IDE)
    2. Install the IDE on the computer(s) that you will be using for this course.
    3. Download the BlueJ Tutorial.
    4. Work through the first 19 pages of the tutorial
  2. August 25: Class Web Page
    1. Set up a class web page.
      • Put your name on the page.
      • Create a section which lists your class projects with links to applets and web pages with detailed discussions when appropriate.
      • Create a section for Java Resources (books, web sites, etc.) that you have checked out and your comments on them.
      • Create a link back to your home page so that the curious can find out more about the other dimensions of your personality and related stuff like resumes.
    2. Send me the url for your class web page.
    3. Check out the information about yourself on the Meet the Class page, and send me an email about any corrections that need to be made. Of course, the link to your class web page will not work until you let me know the url.

  3. August 25: Subscribe to the SafariU Online Bookshelf
    • Surf to SafariU and subscribe to the online bookshelf.
      (O'Reilly refers to the Online Bookshelf as an Online Syllabus.)
      This assignment is no longer required, since O'Reilly has apparently discontinued this service.
      For the basics of Java programming, study the free version of Bruce Eckel's book, Thinking in Java. You can read it online or download it it from his web site. Be sure to familiarize yourself with the other available Java Resources. and the annotated list of books and references.
  4. August 27: Reverse
    1. Set up the HelloWorldApplications project in BlueJ (or the IDE of your choice) using the four Java files that I sent you.
      • MinHelloWorld.java
      • HelloWorld.java
      • Echo.java
      • Echo2.java
    2. Copy the Echo2.java file and create a class called Reverse1. This class should have a single method which echoes the arguments in reverse order. The command line
      java Reverse1 How now brown cow?
      should print out
      cow? brown now How
      This method should not print any additional information other than the reversed list of arguments. This means that you will need to delete some lines from Echo2. It is also the case that you may find the while loop more useful for this exercise than the for loop. Compile and test your code. When it runs correctly email me a copy of the code. The subject line should read "Reverse1.java".
    3. Copy the Reverse1.java file and create a class called Reverse2. This class should have a single method which echoes the arguments in reverse order and prints each argument in reverse order. The command line
      java Reverse2 How now brown cow?
      should print out
      ?woc nworb won woH
      This method should not print any additional information other than the reversed list of reversed arguments. Compile and test your code. When it runs correctly email me a copy of the code. The subject line should read "Reverse2.java".

  5. August 29: Hello World Applet
    1. Copy the html file and the Java source code from my HelloWorld page.
    2. Modify the code (add your name and change the colors).
    3. Compile your code, and set up a page with your own HelloWorld applet.

  6. September 5: Simple Draw Applet with a Circle
    For this project create a web page with an applet that draws rectangles, squares, ellipses, and circles. It should also be able to draw these figures in red, blue, green, orange, and white. Link to this page from your class page. This page should be almost identical to the SimpleDraw Applet Version 1 web page.

    A copy of SimpleDraw1.java was emailed to you, and the source code is also available in the Java Examples section under the SimpleDraw Applet Version 1. You will need to modify SimpleDraw1.java in several places, and you will need to develop a new class called MyCircle, which will be a subclass of m865.shapepack.Ellipse. The source code for the MyCircle class that you develop should look very similar to the source code for m865.shapepack.Square - a copy of which was also emailed to you and discussed in class. The major difference is that your class will not be a member of the m865.shapepack package.

    In addition a jar file, m865.jar, was sent to you. It contains the class files for the m865.shapepack package. To use this package in BlueJ simply add the jar file in the Libraries tab of the BlueJ Preferences dialog. To use the package with your web based applet, put the jar file in the directory which will contain your SimpleDraw1 applet, and extract the class files from the jar file using the command

    jar xvf m865.jar
    The files should automatically be placed in the subdirectory m865/shapepack and your compiler should be able to find them given the source code statements
    import m865.shapepack.Shape;
    import m865.shapepack.Rectangle;
    import m865.shapepack.Ellipse;
    import m865.shapepack.Square;
  7. September 10: Simple Draw Applet with a Shape Factory
    For this project create a web page with an applet that draws rectangles, squares, ellipses, circles, and another shape of your own design. Link to this page from your class page. This page should be almost identical to the SimpleDraw Applet Version 2 web page.

    The important feature of this project is the use of a Factory Design Pattern. A copy of SimpleDraw2.java was emailed to you, and the source code is also available in the Java Examples section under the SimpleDraw Applet Version 2. Unlike the previous exercise, where you had to modify the framework - SimpleDraw1 - in several places, in this exercise you will only modify SimpleDraw2 by commenting out two lines and uncommenting the two following lines. All the information about what shapes can be drawn and how to draw them has been moved out of the framework and into a ShapeFactory class. The API for this class is available online at MTHSC 865 API. SimpleDraw2 has been designed to use this ShapeFactory (or any subclass) to obtain the list of shapes that can be drawn, as well as to construct the shapes themselves. You will write a MyFactory class that extends m865.shapepack.ShapeFactory. This extension will allow the super class to do all the things that it already does and will enhance it so that the MyCircle class and the class for your "designer shape" are incoporated cleanly into the applet.

    You will use the MyCircle class developed in the previous exercise, and you will write two new classes - the MyFactory class and the class for your "designer shape". The web page that contains your applet should also contain links to the source code for your MyFactory class, for your "designer shape" class, and for your slightly modified SimpleDraw2 class.

    The new jar file that was sent to you contains the class file m865.shapepack.ShapeFactory, and a copy of the source code for m865.shapepack.ShapeFactory was emailed to you. One of your goals is to maximize code reuse. In other words, do not write code to do anything that ShapeFactory can already do.

  8. September 17: QueueAL Implementation and Timing
    1. Write a version of QueueAL, an implementation of a FIFO queue using a java.util.ArrayList, similar in many respects to the StackAL. A good way to get started is to globally replace all occurences of Stack by Queue and stack by queue. Also change the name of the ArrayList from s to q. Then proceed to change the push and pop methods to enqueue and dequeue. At this point the compiler will be helpful in pinning down the remaining changes.
    2. As discussed in class some of you should implement your queue so that the back of the queue is at q[0] and the front of the queue is at q[n-1]. The rest of you should do exactly the opposite. Include a main method that includes the appropriately altered set of tests included in the main method for StackAL.
    3. You have also received a copy of QueueALTimer.java. Use this code to perform timing studies on your queue implementation. In particular, collect data for n = {100, 500, 1000, 5000, 10000, 25000, 50000}.
    4. Enter your data into a spreadsheet and generate a plot of the times versus n.
    5. Create a web page that contains a table of your data, a picture of your data plot, a link to your QueueAL source code, and a brief paragraph summarizing your analysis and pointing out any surprising or less than ideal behavior.
    6. Do not link to this HW08 page from your class page until the day the project is due. You can email me your QueueAL.java file as soon as you have it running correctly and the url for your HW08 page as soon as you have finished it.
  9. September 22: QueueLL Implementation and Timing
    1. Write a single version of QueueLL, an implementation of a FIFO queue using a Linked List, similar in many respects to the StackLL example. A good way to get started is to globally replace all occurences of Stack by Queue and stack by queue. Also replace the Link labeled top with two Links labeled front and back. Then proceed to change the push and pop methods to enqueue and dequeue. Include a main method that includes the appropriately altered set of tests included in the main method for StackLL.
    2. You will also receive a copy of QueueLLTimer.java. Use this code to perform timing studies on your queue implementation. In particular, collect data for n = {100, 500, 1000, 5000, 10000, 25000, 50000}.
    3. Enter your data into a spreadsheet and generate a plot of the times versus n.
    4. Create a web page that contains a table of your data, a picture of your data plot, a link to your QueueLL source code, and a brief paragraph summarizing your analysis and pointing out any surprising or less than ideal behavior.
    5. Modify the QueueLLTimer.java and test the queue methods for java.util.LinkedList. Create a second web page that contains a table of your data for the java.util.LinkedList, a picture of your data plot, and a brief paragraph summarizing your analysis and pointing out any surprising or less than ideal behavior.
    6. Do not link to this HW09 page from your class page until the day the project is due. You can email me your QueueLL.java file as soon as you have it running correctly and the url for your HW09 page as soon as you have finished it.