Question: Write a Java program to read the Marvel universe social network from the csv files nodes.csv, edges.csv, and hero-network.csv. Hi I wrote some code and

Write a Java program to read the Marvel universe social network from the csv files nodes.csv, edges.csv, and hero-network.csv.

Hi I wrote some code and may I get help to solve this problem. The output shoud be like this:

Number of characters: 6486 Number of books: 12942 Mean books per character: 14.9 Mean characters per book: 7.47 Mean partners per hero: 5.43

my code prints only Number of characters: and Number of books: I want help with other three outputs please.

my Code is here:

package NewP; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.*;

public class Main {

public static void main(String[] args) {

String csvFile1 = "Files/edges.csv"; String csvFile2 = "Files/hero-network.csv"; String csvFile3 = "Files/nodes.csv"; BufferedReader br = null; String line = ""; String cvsSplitBy = ","; int heroCount = 0; int comicCount = 0; int bookNumber = 0; int partnerNum = 0; int charNum = 0; List heroList = new ArrayList(); List comicList = new ArrayList(); Map typeMap = new HashMap();

try { // read comics or characters from the nodes.csv and count them br = new BufferedReader(new FileReader(csvFile3)); br.readLine();

while ((line = br.readLine()) != null) { // use comma as separator, it ignores the comma between quotes. String[] arrFile3Line = line.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);

if (arrFile3Line[1].equalsIgnoreCase("comic")) { comicCount++; } if (arrFile3Line[1].equalsIgnoreCase("hero")) { heroList.add(arrFile3Line[0]); heroCount++; } } System.out.println("Number of heroes : " + heroCount); System.out.println("Number of comics : " + comicCount);

} catch (FileNotFoundException e) { e.printStackTrace();

} catch (IOException e) { e.printStackTrace();

} finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } }

for more explanation:

nodes.csv Contains two columns, node and type. Each row defines a node in the social

network. Node is the name of the node and type is either hero or comic.

edges.csv Contains two columns, hero and comic. Each row defines an edge from a hero node

to a comic node in the social network.

hero-network.csv Contains two columns, hero1 and hero2. Each row defines an instance of

two heroes appearing in a single comic.

(coma separates the hero and comic in edges.csv and inside the edges.csv file contains hero and comic)

(Comic is string followed by number, I assume it is just a name)

edges.csv

hero,comic

24-HOUR MAN/EMMANUEL,AA2 35

3-D MAN/CHARLES CHAN,AVF 4

3-D MAN/CHARLES CHAN,AVF 5

3-D MAN/CHARLES CHAN,COC 1

3-D MAN/CHARLES CHAN,H2 251

3-D MAN/CHARLES CHAN,H2 252

3-D MAN/CHARLES CHAN,M/PRM 35

3-D MAN/CHARLES CHAN,M/PRM 36

3-D MAN/CHARLES CHAN,M/PRM 37

3-D MAN/CHARLES CHAN,WI? 9

4-D MAN/MERCURIO,CA3 36

4-D MAN/MERCURIO,CM 51

4-D MAN/MERCURIO,Q 14

4-D MAN/MERCURIO,Q 16

4-D MAN/MERCURIO,T 208

4-D MAN/MERCURIO,T 214

4-D MAN/MERCURIO,T 215

4-D MAN/MERCURIO,T 216

4-D MAN/MERCURIO,T 440

8-BALL/,SLEEP 1

8-BALL/,SLEEP 19

8-BALL/,SLEEP 2

total 96,501 lines

Note: (here coma separates the hero1 and hero2 inside the hero-network.csv file contains hero1 and hero2)

hero-network.csv

hero1,hero2

"LITTLE, ABNER","PRINCESS ZANDA"

"LITTLE, ABNER","BLACK PANTHER/T'CHAL"

"BLACK PANTHER/T'CHAL","PRINCESS ZANDA"

"LITTLE, ABNER","PRINCESS ZANDA"

"LITTLE, ABNER","BLACK PANTHER/T'CHAL"

"BLACK PANTHER/T'CHAL","PRINCESS ZANDA"

"STEELE, SIMON/WOLFGA","FORTUNE, DOMINIC"

"STEELE, SIMON/WOLFGA","ERWIN, CLYTEMNESTRA"

"STEELE, SIMON/WOLFGA","IRON MAN/TONY STARK "

"STEELE, SIMON/WOLFGA","IRON MAN IV/JAMES R."

"STEELE, SIMON/WOLFGA","RAVEN, SABBATH II/EL"

"RAVEN, SABBATH II/EL","FORTUNE, DOMINIC"

"RAVEN, SABBATH II/EL","ERWIN, CLYTEMNESTRA"

"RAVEN, SABBATH II/EL","IRON MAN/TONY STARK "

"RAVEN, SABBATH II/EL","IRON MAN IV/JAMES R."

"IRON MAN IV/JAMES R.","FORTUNE, DOMINIC"

"IRON MAN IV/JAMES R.","ERWIN, CLYTEMNESTRA"

"IRON MAN IV/JAMES R.","IRON MAN/TONY STARK "

"IRON MAN/TONY STARK ","FORTUNE, DOMINIC"

"IRON MAN/TONY STARK ","ERWIN, CLYTEMNESTRA"

total 574,468 lines

Note: (here coma separates the node and type, and inside the nodes.csv file contains node and type)

nodes.csv

node,type

2001 10,comic

2001 8,comic

2001 9,comic

24-HOUR MAN/EMMANUEL,hero

3-D MAN/CHARLES CHAN,hero

4-D MAN/MERCURIO,hero

8-BALL/,hero

A '00,comic

A '01,comic

A 100,comic

A 101,comic

total 19,901 lines

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!