SHARE
TWEET

Untitled

a guest Apr 1st, 2019 153 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.HashMap;
  2.  
  3. public class SymbolTable {
  4.  
  5.     private final String ALL_VALID_CHARS = "1234567890()@zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP_;";
  6.     private final String INITIAL_VALID_CHARS = "@MDA(";
  7.     HashMap<String, String> map;
  8.  
  9.     // DESCRIPTION:   initializes hashmap with predefined symbols
  10.     // PRECONDITION:  follows symbols/values from book/appendix
  11.     // POSTCONDITION: all hashmap values have valid address integer
  12.     public SymbolTable() {
  13.         map = new HashMap<>();
  14.     }
  15.  
  16.  
  17.     // DESCRIPTION:   adds new pair of symbol/address to hashmap
  18.     // PRECONDITION:  symbol/address pair not in hashmap (check contains() 1st)
  19.     // POSTCONDITION: adds pair, returns true if added, false if illegal name
  20.     public boolean addNewEntry(String symbol, int adress) {
  21.  
  22.         return false;
  23.     }
  24.  
  25.     // DESCRIPTION:   returns boolean of whether hashmap has symbol or not
  26.     // PRECONDITION:  table has been initialized
  27.     // POSTCONDITION: returns boolean if arg is in table or not
  28.     public boolean contains(String symbol) {
  29.  
  30.         return false;
  31.     }
  32.  
  33.     // DESCRIPTION:   returns address in hashmap of given symbol
  34.     // PRECONDITION:  symbol is in hashmap (check w/ contains() first)
  35.     // POSTCONDITION: returns address associated with symbol in hashmap
  36.     public int getAdress(String symbol) {
  37.  
  38.         return 0;
  39.     }
  40.  
  41.     //same as part 1 but rewrite using constants
  42.     public boolean isValidName(String symbol) {
  43.  
  44.         return false;
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top