Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Edit java program output. I wanted to have the output in the same format as the

ID: 3847488 • Letter: E

Question

Edit java program output. I wanted to have the output in the same format as the input. The string that is tabbed is a subset of the first. There can be more than one subset, but there is always one subset. End the program if there are two blank lines in a row.

input:

rabc

(tab) be

(tab) ton

prj

(tab) eye

rcf

(tab) bat

________________________________________________________________________

desired output:

prj

(tab) eye

rabc

(tab) be

(tab) ton

rcf

(tab) bat

import java.io.*;
import java.util.*;

public class jobHuntOrganizer {

public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("jobList.txt"));
Map < String, String > map = new TreeMap < String, String > ();
String line = "";
while ((line = reader.readLine()) != null) {
// System.out.println(line);
map.put(getField(line), line);
}
reader.close();
FileWriter writer = new FileWriter("jobList.txt");
for (String val: map.values()) {
//writer.write(val);
//writer.write(' ');
}
writer.close();
}

private static String getField(String lines) {
return lines;
}
}

not desired output

(tab) eye

(tab) be

(tab) ton

(tab) bat

prj

rabc

rcf

Explanation / Answer

mport java.io.*;
import java.util.*;

public class jobHuntOrganizer {

public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("jobList.txt"));
Map < String, String > map = new TreeMap < String, String > ();
String line = "";
while ((line = reader.readLine()) != null) {

if(line.startsWith("("))

{

words[i]=line;

++i;

}

else

{

map.put(getField(line),line);

}

}
// System.out.println(line);
map.put(getField(line), line);
}
reader.close();
FileWriter writer = new FileWriter("jobList.txt");
for (String val: map.values()) {
writer.write(val);
writer.write(' ');
}
writer.close();
}

for(int j=0;j<words.length;j++)

{

if(words[j].equals("(tab)eye"))

{

String temp=words[j];

String word=words[0];

words[0]=temp;

words[j]=word;

}

}

for(String word1 :words)

{

System.out.println(word1);

}

}

private static String getField(String lines) {
return lines;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote