I cannot compile this program which from a file with this format (where "Via" is the italian for "road")
Via Emilia-->Via Botti
Via Castello-->Via Emilia
Via Appia-->Via Botti
Via Botti-->Via Emilia
Via Castello-->Via Amendola
Via Appia-->Via Ancona
Via Castello-->Via Botti
Via Matteotti-->Via Carso
Via Ancona-->Via Matteotti
Via Carso-->Via Matteotti
And at the third questions asks me to find which roads are recursive one into another (like a->b and b->a), but when I try to put conditions to remove the possibility of having duplicate answers (like a and b are recursive and b and a are recursive) I get this error "java.util.ConcurrentModificationException", what does it mean?
This is the main
public static void main(String[] args) throws Exception{
ArrayList<percorso> perc = new ArrayList<percorso>();
String line;
BufferedReader br = new BufferedReader(new FileReader("vie.txt"));
while ((line = br.readLine())!=null){
percorso p = new percorso (null,null);
String [] e = line.split("-->");
p.from = e[0];
p.to = e[1];
perc.add(p);
}
br.close();
//punto1(perc);
//punto2(perc);
punto3(perc);
}
This is the method to compile the answer at the third question
public static void punto3(ArrayList<percorso> perc) throws Exception{
BufferedWriter bw=new BufferedWriter(new FileWriter("3.html"));
bw.write("<html> \n <body> \n");
bw.write("<h1> Punto 3 </h1> \n");
bw.write("<h3><i> Trovare le coppie di strade che formano un anello chiuso </h3></i> \n");
ArrayList<percorso> perc2 = new ArrayList<percorso>();
for (percorso k: perc)
perc2.add(k);
ArrayList<String[]> Arr = new ArrayList<String[]>();
for (percorso i: perc2){
for (percorso j: perc2){
if (i.from.equals(j.to) && i.to.equals(j.from)){
String [] e = {i.from,i.to};
Arr.add(e);
}
}
}
ArrayList<String[]> Arr2 = new ArrayList<String[]>();
for (String [] z: Arr){
Arr2.add(z);}
for (String [] f: Arr){
for (String [] j: Arr2){
if (f[0].equals(j[1]) && j[0].equals(f[1]))
Arr.remove(j);
}
}
for (String [] x: Arr)
bw.write("le vie "+x[0]+", "+x[1]+" formano un anello chiuso <br>");
bw.write("</body> \n </html> \n");
bw.close();
}
And the class percorso is the following
public class percorso {
String from;
String to;
public percorso (String from,String to){
this.from = from;
this.to = to;
}
}