/** * A4Q1: Purpose of this program is to execute 'milen' programs and store the variables in a hashtable * COMP 2140 SECTION L01 * INSTRUCTOR Helen Cameron * ASSIGNMENT Assignment #4, Question #1 * AUTHOR Jonathan Chartrand, 6818334 * VERSION November 15th, 2007 */ import java.io.*; public class A4Q1 { //********************************************************************** /** Node * PURPOSE: Node class which is used to store a variable's name and its corresponding value for a milen program. Nodes are used so the program can employ the separate chaining method. */ static class Node { int number = 0; String name = null; Node next = null; //******************** //Constructor //******************** public Node(String name, int number, Node next) { this.name = name; this.number = number; this.next = next; } //******************** //Accessors //******************** public String getName() { return name; } public int getNum() { return number; } public Node getNext() { return next; } //******************** //Mutators //******************** public void setName(String name) { this.name = name; } public void setNum(int number) { this.number = number; } public void setNext(Node next) { this.next = next; } } ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// //********************************************************************** /** Hashtable * PURPOSE: stores a variable with its corresponding value into a hashtable. position in which information is stored is based on the variable's name using Horner's method. */ static class Hashtable { int size = 0; Node[] table; int constant = 23; int elements = 0; //******************** //Constructor //******************** public Hashtable() { size = 79; table = new Node[size]; } //******************** //Methods //******************** /**printVariables * PURPOSE: prints all the variables and their corresponding value contained in the hashtable * PARAM: none * RETURN: void */ public void printVariables() { for (int i=0;i