Dictionary class to include exceptions so that when you run


Edit the Dictionary class to include exceptions so that when you run the class DictionaryTest, all tests pass. For example, the method put in the class Dictionary should include the following exception handling:

public void put(String key, Token value) {

if (key == null || value == null) {
throw new NullPointerException("key or value is null");
}

if (count == elems.length) {
increaseCapacity();
}

// Similarly to the array-based implementation
// of a stack, I am adding elements at the end
elems[count] = new Pair(key, value);
count++;
}

LukaSyntaxException

  • Define a new run-time exception named LukaSyntaxException.
  • Make changes to the class Interpreter so that when the following situations are detected, an exception of type LukaSyntaxException is thrown.
    • When an illegal symbol has been found. All illegal symbols are symbols that is nor a reserved keyword (operation), nor an existing association in the dictionary.(Note nor is a Boolean operator that gives the value one if and only if all operands have a value of zero and otherwise has a value of zero.)
    • When undefining a non-existing association.
    • When updating a non-existing association.
  • The class Interpreter will display the appropriate messages, including:
    • The symbol table.
    • Operands stack.
  • Make changes to the class Viewer so that exceptions of type LukaSyntaxException are caught. When catching the exception, the method displays the type of the exception and its message. Finally, the application exits.

For instance, upon executing the following Luka program:

/x 1 def /y 2 def x y /z 3 set

The application would print the following information and exit.

LukaSyntaxException: 
Dictionary: {elems = [{key=y,value=2}, {key=x,value=1}]}
DynamicArrayStack: {3,z,2,1}
ILLEGAL SYMBOL: set
caught LukaSyntaxException

Attachment:- Luka.zip

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Dictionary class to include exceptions so that when you run
Reference No:- TGS02384603

Now Priced at $15 (50% Discount)

Recommended (91%)

Rated (4.3/5)