For this assignment, you will create a portion of a retail store checkout system. For this assignment you have both data structures and an application to develop. The application provides fast lookup for product information. A clerk (or customer) inputs a product stock number and the system returns the record for that item. The system is designed to provide facilities to add, remove and look up items, along with certain other utility functions.
This program consists of the ProductLookup application program, which allows the user to interact with the dictionary. You will implement the DictionaryADT interface in three ways:
Your project will consist of the following files:
ProductLookup.java | The application program (methods below). |
StockItem.java | The items that are stored in the dictionary. |
DictionaryADT.java | The Dictionary interface. (Provided) |
Hashtable.java | A hash table implementation of the DictionaryADT interface. Using chaining. |
BinarySearchTree.java | The BST implementation of the DictionaryADT. |
BalancedTree.java | A red/black tree implementation of the DictionaryADT, which uses the Java API class java.util.TreeMap. |
You will write all of the above classes with the exception that the two interfaces are provided.
You may not make any modifications the Dictionary ADT interface; the instructor's copy of this file will be used to grade your project.
All of the above classes except ProductLookup.java and StockItem.java must be in a package named data_structures.
ProductLookup.java
import data_structures.*;
import java.util.Iterator;
public class ProductLookup {
// Constructor. There is no argument-less constructor, or default size
public ProductLookup(int maxSize)
// Adds a new StockItem to the dictionary
public void addItem(String SKU, StockItem item)
// Returns the StockItem associated with the given SKU, if it is
// in the ProductLookup, null if it is not.
public StockItem getItem(String SKU)
// Returns the retail price associated with the given SKU value.
// -.01 if the item is not in the dictionary
public float getRetail(String SKU)
// Returns the cost price associated with the given SKU value.
// -.01 if the item is not in the dictionary
public float getCost(String SKU)
// Returns the description of the item, null if not in the dictionary.
public String getDescription(String SKU)
// Deletes the StockItem associated with the SKU if it is
// in the ProductLookup. Returns true if it was found and
// deleted, otherwise false.
public boolean deleteItem(String SKU)
// Prints a directory of all StockItems with their associated
// price, in sorted order (ordered by SKU).
public void printAll()
// Prints a directory of all StockItems from the given vendor,
// in sorted order (ordered by SKU).
public void print(String vendor)
// An iterator of the SKU keys.
public Iterator< String> keys()
// An iterator of the StockItem values.
public Iterator< StockItem> values()
}
StockItem.java
import java.util.Iterator;
import data_structures.*;
public class StockItem implements Comparable{
String SKU;
String description;
String vendor;
float cost;
float retail;
// Constructor. Creates a new StockItem instance.
public StockItem(String SKU, String description, String vendor,
float cost, float retail)
// Follows the specifications of the Comparable Interface.
// The SKU is always used for comparisons, in dictionary order.
public int compareTo(StockItem n)
// Returns an int representing the hashCode of the SKU.
public int hashCode()
// standard get methods
public string getDescription()
public String getVendor()
public float getCost()
public float getRetail()
// All fields in one line, in order
public String toString()
}
DictionaryADT
/* DictionaryADT.java
Dictionary interface.
*/
package data_structures;
import java.util.Iterator;
import java.util.NoSuchElementException;
public interface DictionaryADT< K extends Comparable< K>,V> {
// Returns true if the dictionary has an object identified by
// key in it, otherwise false.
public boolean contains(K key);
// Adds the given key/value pair to the dictionary. Returns
// false if the dictionary is full, or if the key is a duplicate.
// Returns true if addition succeeded.
public boolean add(K key, V value);
// Deletes the key/value pair identified by the key parameter.
// Returns true if the key/value pair was found and removed,
// otherwise false.
public boolean delete(K key);
// Returns the value associated with the parameter key. Returns
// null if the key is not found or the dictionary is empty.
public V getValue(K key);
// Returns the key associated with the parameter value. Returns
// null if the value is not found in the dictionary. If more
// than one key exists that matches the given value, returns the
// first one found.
public K getKey(V value);
// Returns the number of key/value pairs currently stored
// in the dictionary
public int size();
// Returns true if the dictionary is at max capacity
public boolean isFull();
// Returns true if the dictionary is empty
public boolean isEmpty();
// Returns the Dictionary object to an empty state.
public void clear();
// Returns an Iterator of the keys in the dictionary, in ascending
// sorted order. The iterator must be fail-fast.
public Iterator< K> keys();
// Returns an Iterator of the values in the dictionary. The
// order of the values must match the order of the keys.
// The iterator must be fail-fast.
public Iterator< V> values();
}
Additional Details: