Question: 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 Notes:

 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


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 2 3 0

Tryptophan

TGG

Cysteine

TGT TGC



>java LookupMultipleNumber amino.csv 6 3 0

Cysteine

TGT TGC

Leucine

TTA TTG CTT CTC CTA CTG






2. Modify the "Graph" program given in the textbook (program 4.5.1) to create a program, "SubGraph". It would take a filename and vertices as input arguments on the command line. It would create and print out a graph using the data specified in the file (as is done by the "Graph" program). And then it would also print out the subgraph of the graph formed by the vertices that are given on the command line. [MO7.2]


Note: The induced subgraph is the graph comprised of the specified vertices together with all edges from the original graph that connect any two of them.


  • The input and output of the program should be similar to, or as specified by, the following sample run.



>more graph.txt

A B

A C

C G

A G

H A

B C

B H


>java SubGraph graph.txt A C G

The graph is

A: B C G H

B: A C H

C: A B G

G: A C

H: A B

The subgraph is

A: C G

C: A G

G: A C

4.4 Symbol Tables Program 4.4.1 Dictionary lookup public class Lookup { vinopublic static void main(String[] args) { // Build dictionary, provide values for

4.4 Symbol Tables Program 4.4.1 Dictionary lookup public class Lookup { vino public static void main(String[] args) { // Build dictionary, provide values for keys in StdIn. In in = new In (args[0]); pub int keyField = Integer.parseInt(args[1]); int valField = Integer.parseInt(args[2]); String[] database = in.readA11Lines(); 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 String val tokens [keyField]; = tokens [valField]; Bilgm st.put(key, val); rol) } while (!StdIn.isEmpty()) 631 in keyField valField input stream (.csv) key position value position art blind database[] lines in input { // Read key and provide value. String s = StdIn.readString(); StdOut.println(st.get(s)); MA) obn } } } 46 st tokens symbol table (BST) values on a line key key val 172 10 99013 S value query This ST client reads key-value pairs from a comma-separated file, then prints values corre- sponding to keys on standard input. Both keys and values are strings. indyad % java Lookup amino.csv 03 1 1er abja % java Lookup ip.csv 0 1 TTA Leucine ABC null TCT Serine % java Lookup amino.csv 30 Glycine GGG www.google.com 216.239.41.99 % java Lookup ip.csv 1 0 216.239.41.99 www.google.com % java Lookup DJIA.csv 0 1 29-Oct-29 og gratista 252.38

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure based on the image you sent it appears to be a continuation of the code for the LookupMultipleNumber program Heres a breakdown of the code and th... View full answer

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 Programming Questions!