Question: Modify the Lookup program given in the textbook ( program 4 . 4 . 1 ) to make a program LookupMultipleNumber that prints out multiple

Modify the Lookup program given in the textbook (program 4.4.1) to make a program LookupMultipleNumber that prints out multiple values having the same key. [MO7.1]
Notes:
The user would specify the maximum number of values to be printed out for each key as a command line argument after the file name.
Store all such multiple values in a queue. So each element of the symbol table would have a string as a key and a queue object as its value.
Sample runs would be as follows (refer to input file amino.csv)
>java LookupMultipleNumber amino.csv 230
Tryptophan
TGG
Cysteine
TGT TGC
Program 4.4.1 Dictionary lookup
public class Lookup
public static void main(String[] args){
// Build dictionary, provide values for keys in StdIn.
In in = new In (args[0]);
int keyField = Integer.parseInt(args[1]);
int valField = Integer.parseInt(args[2]);
String[] database = in.readAllLines();
StdRandom.shuffle (database);
ST st = new ST();
for (int i =0; i < database.length; i++)
{// Extract key, value from one line and add to ST.
String [] tokens = database[i].split(",");
String key = tokens [keyField];
String val = tokens [valField];
st.put(key, val);
}
while (!StdIn.isEmpty())
{// Read key and provide value.
String s = StdIn.readString();
StdOut.println(st.get(s));
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!