Question: JAVA HELP here is what I have, I need the BufferedReader to read file references.ris and BufferedWriter to write into output.txt import java.util.Map; import java.io.BufferedReader;

JAVA HELP

here is what I have, I need the BufferedReader to read file "references.ris" and BufferedWriter to write into "output.txt"

import java.util.Map;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.IOException;

import java.io.*;

import java.util.*;

public class Ris01 {

public static void main(String[] args) throws IOException {

try (BufferedReader in = new BufferedReader(new InputStreamReader("references.ris"))) {

try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter("output.txt"))) {

Set doSet = new HashSet<>();

Map kwCount = new HashMap<>();

String line, doValue = "", tiValue = "", longestTagValue = "", mostKW = "";

int uniqueCount = 0, numOfAuthors = 0, maxKWCount = 0;

boolean validEntry = true;

while ((line = in.readLine()) != null) {

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

if (parts.length != 2) continue;

String tag = parts[0].trim();

String value = parts[1].trim();

if (tag.equals("TY")) {

if (doValue.length() > 0) {

if (validEntry) {

out.write("SM - UniqueCount: " + uniqueCount + ", NumOfAuthors: " + numOfAuthors + ", LongestTagValue: " + longestTagValue + ", MostKW: " + mostKW);

out.newLine();

}

doValue = "";

tiValue = "";

longestTagValue = "";

mostKW = "";

uniqueCount = 0;

numOfAuthors = 0;

maxKWCount = 0;

validEntry = true;

}

if (!value.equals("CONF")) {

validEntry = false;

out.write("Invalid entry at TY: " + tiValue);

out.newLine();

}

} else if (tag.equals("DO")) {

if (doSet.contains(value)) {

validEntry = false;

out.write("Duplicate DO: " + value + " for Title: " + tiValue);

out.newLine();

} else {

doSet.add(value);

doValue = value;

}

} else if (tag.equals("TI")) {

tiValue = value;

} else if (tag.equals("AU")) {

numOfAuthors++;

} else if (tag.equals("KW")) {

uniqueCount++;

if (value.length() > longestTagValue.length()) longestTagValue = value;

kwCount.put(value, kwCount.getOrDefault(value, 0) + 1);

}

for (Map.Entry entry : kwCount.entrySet()) {

if (entry.getValue() > maxKWCount) {

maxKWCount = entry.getValue();

mostKW = entry.getKey();

}

}

}

if (validEntry) {

out.write("SM - UniqueCount: " + uniqueCount + ", NumOfAuthors: " + numOfAuthors + ", LongestTagValue: " + longestTagValue + ", MostKW: " + mostKW);}

}

}

}

}

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!