Programming Assignment

Due:

Please make sure you adhere to the policies on academic honesty.

Please see the general programming webpage for details about the programming environment for this course, and specifically for directions in how to submit your programming assignment electronically.

The files you need for this assignment can be downloaded here.


Contents:

  • Overview
  • Files to Submit
  • Your Task
  • Readme File
  • Test Input
  • Files you will need
  • Drivers
  • Grading Standards
  • Hints regarding Modular Arithmetic

  • Overview

    Web browsers commonly allow you to navigate through a "history" of web pages which have previously been visited. Example 4.1 of the textbook suggests that a stack ADT might be used to maintain this history, allowing the user to step "back" to get to the previously visited sites. If a web browser could hold infinitely many entries in its history, then this analogy might be valid. In reality, there may generally exist some fixed limit on the size of the history.

    If the history must exist with a fixed maximum capacity, one approach may be to use the ArrayStack implementation of a Stack, as given in Code Fragment 4.4-4.5 of the text. In the case where an item is pushed onto an already full stack, this implementation throws up its hands (i.e., throws an Exception).

    This is not how your Web browser behaves. If it only has room to save 50 pages in its history and yet you visit more pages, it will make room in the history for a new page by throwing away the page which is on the very bottom of the history (i.e., the least recently visited page). The formal Stack interface does not help, as it gives us no way to directly access or remove the object on the bottom of the stack.

    In this assignment, we define a new ADT which we call a WebHistory. The interface for a WebHistory is very similar to the interface given for a Stack. However in the case when the capacity is exhausted, a call to push will result in the placement of the new page at the expense of the loss of the least recently accessed page. The interface is provided online in a file WebHistory.java.

    /**
     * Interface for a web history: a collection of objects
     * that are inserted and removed according to the 
     * last-in first-out principle, but with overflow handled
     * by the removal of the least-recently accessed item.
     * 
     * @author Michael Goldwasser
     * @see WebHistoryEmptyException
     *
     * Any class which implements this interface should allow
     * a constructor which takes an integer parameter specifying
     * the maximum number of elements which the history will hold
     * e.g., 
     *          public class MyWebHistory implements WebHistory {
     *            public MyWebHistory(int maximum) {
     *               // set the maximum history size
     *            }      
     *          }      
     */
    
    public interface WebHistory {
      /**
       * @return number of elements in the history.
       */
      public int size();
    
      /** 
       * @return true if the history is empty, false otherwise. 
       */
      public boolean isEmpty();
    
      /** 
       * @return top element in the history.
       * @exception WebHistoryEmptyException if the history is empty. 
       */
      public Object top() throws WebHistoryEmptyException;  
    
      /**
       * Insert an element at the top of the history making room, if
       * necessary, by removing the item at the bottom of the history.
       * @param element element to be inserted.
       */
      public void push (Object element); 
    
      /** 
       * Remove the top element from the history
       * @return element removed.
       * @exception WebHistoryEmptyException if the history is empty.
       */
      public Object pop() throws WebHistoryEmptyException; 
    }
    


    Files to Submit

    You should submit the following files,
    WebHistoryA.java, WebHistoryB.java, readme and inputfile,
    as detailed below.

  • Your Task

    For this assignment, you will be required to give two different implementations for the WebHistory interface, as described below. We will provide you with template files for these classes which you can modify.

  • Readme File

    For each assignment, you are to submit a separate file "readme" as specified in the general programming webpage. For this assignment, you should include two separate tables, similar to Table 4.1 on page 144 of the text, summarizing the worst-case asymptotic running times for your implementations. One table should discuss WebHistoryA and one should discuss WebHistoryB.

  • Test Input

    Part of developing good software is also knowing how to develop meaningful input for testing your software. For this reason, we are going to ask you to submit a file named "inputfile" which can be used to test other students' programs. The goal is to create test input which causes as many as possible of the other students' programs to fail in some way. (Please note that your goal is to cause mistakes in the student-written routines. You will not get credit for finding mistakes in the driver which we provide, although you should certainly report any such bugs directly to us.)

    Please note that our input competition will be graded using automation. Therefore, you must make sure that your "inputfile" strictly adheres to the file format which is expected by the the text-based driver, WebHistoryDriver, which we describe below. In order to make sure that your inputfile follows the proper format, we strongly recommend that you run your program on your inputfile to make sure it is accepted by the driver.

    Your file may use at most 100 commands. If your input file contains more than the prescribed number of commands, we will simply truncate the end of the file.

    Here is a sample input file, appropriately formatted.


  • Files you will need

    The files you need for this assignment can be downloaded here.
  • Drivers

    We will provide you with two different drivers which you may find very helpful in testing your implementations. One driver is menu-driven, using text input from either the keyboard or a file. The other driver is an "Applet" which has a graphical user interface.


  • Grading Standards

    The assignment is worth 10 points. Eight points will be awarded based on our own evaluation of your assignment and the readme file. One additional point will be awarded fractionally based on how well your program performs on other students' test inputs. The final point will be awarded fractionally based on how well your test input fools other students' flawed programs.


    Hints Regarding Modular Arithmetic

    When dealing with an array in a circular fashion, there are many possible ways for adjusting indicies as they "wrap around" the ends of the array. The text chooses to use modular arithmetic (the "%" operator in Java). Further discussion of this topic can be found in the general programming webpage.


    Last modified: 11 September 2002