Question

In Java code, for a topological sort assignment: How I load a .txt file and use...

In Java code, for a topological sort assignment:

How I load a .txt file and use its information to populate a hashtable that maps IDs to characters, and add the IDs as nodes in the graph.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:-

/* I WRITE A CODE /*

public static void main(string[ ] args) throws I O Exception

{

String file Path= "test ,t x t";

hash Map<string ,String > map = new (Hash Map<String,String>( );

String line;

Buffered Reader reader = new Buffered Reader(new File Reader(file path));

while ((line = reader .read Line( ) ) !=NULL)

{

String[ ] parts = line .split(" : " ,2);

if ( parts. length >=2)

{

String Key = Parts[0];

String value = parts[1];

map.put(key , value);

} else{

System . out . print l n("ignoring line :" +line);

}

}

for( String Key :map .key Set ( ) )

{

System.out.print l n( key + ":" +map.get(key));

}

reader.close( );

}

  

Add a comment
Know the answer?
Add Answer to:
In Java code, for a topological sort assignment: How I load a .txt file and use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In the following graph, write a Java program using Topological Sort. please write java code and...

    In the following graph, write a Java program using Topological Sort. please write java code and show me the output. Thank you :) b.

  • JAVA - Natural Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file...

    JAVA - Natural Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file like below and must use a Quick sort Algorithm ================ 6 10 4 19 10 12 8 6 0 1 2 3 ================ The first number "6" represents the index of the element to return after sort the second number on the top "10" represents the number of elements or size of array. The following numbers and lines are the elements that need to...

  • how do you load text from a txt file in java

    how do you load text from a txt file in java

  • Shortest Path (DAG) Students, In this coding assignment, you will be asked to write Java code...

    Shortest Path (DAG) Students, In this coding assignment, you will be asked to write Java code to read a text file (input.txt) of a graph represented as an adjacency list. Example: A, 7, B, 9, C B, 1, C C, 8, E, 2, F D, 1, E, 3, G E, 3, G F, 3, D, -3, H H, 6, G K, 3, H, -1, F The graph represented by the adjacency list above looks like this: The graph is a...

  • using java create hash set that can for the file use a txt file: Hi my...

    using java create hash set that can for the file use a txt file: Hi my name is rick. (a) Read one word from the file. (b) Remove all non-alphanumeric characters from the word. A non-alphanumeric character is any character other than the lowercase and uppercase English letters, and the numerals 0 through 9. (c) Add the modified word to the hash set.

  • Using java: Store the files in .txt format and use the readByte() and writeByte() methods. File...

    Using java: Store the files in .txt format and use the readByte() and writeByte() methods. File encryption is the science of writing the contents of a file in a secret code. Write an encryption program that works like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code....

  • Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS...

    Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS algorithm. Your program should read an input file name and determine if the input graph is a DAG (= directed acyclic graph) or not. If the graph is not a DAG, your program has to stop without further processing. However, if it’s a DAG, your program should display the starting node(s), popping-off order, and topologically sorted list. In the problem, you can assume that...

  • Help on writing a MATLAB code. Let's say i am given a .txt file and in...

    Help on writing a MATLAB code. Let's say i am given a .txt file and in that text file there are 26 rows that represent individual students grades and then 7 columns that represent specific homework assignments. We want to ask the user to select a specific homework assignment and output the mean and standard deviation for that assignment. Then we want to ask the user to select an individual student and output the mean and standard deviation for that...

  • Please provide C language code no c++ ,txt file also needed with comment Finish task 5...

    Please provide C language code no c++ ,txt file also needed with comment Finish task 5 Task5: Breadth First Search (15 pts) · Write a program to read the graph information from the file and traverse the graph using BFS algorithm as introduced in lecture. The input for each algorithm is an undirected unweighted connected graph stored in a local file using an adjacency list. Following is the example of the input file (graph.txt) and the graph First line is...

  • I have the code DebugDataOne1.txt Somewhere over the rainbow. DebugDataOne2.txt There's no place like home. Are...

    I have the code DebugDataOne1.txt Somewhere over the rainbow. DebugDataOne2.txt There's no place like home. Are you a good witch or a bad witch? DebugThirteen1.java import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { try { Path file1 = Paths.get("C:\\Java\\Chapter.13\\\\DebugData1.txt"); Path file2 = Paths.get("C:\\Java\\Chapter.13\\\\DebugData2.txt");// Please use the path of the file from where you want to access it. BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class); System.out.println("File: " + file1.getFileName()); System.out.println("Creation time " + attr1.creationTime()); System.out.println("Last...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT