This is my task. If there are some grammar mistakes it is because it is transelated from slovenian.
In the company, they have a large amount of data, which they store in files. Records consist of letters and/or numbers (without spaces). One day, one of the careless workers accidentally uploaded a virus to the company’s computers, which fragmented the contents of the files into smaller parts and mixed them together. The virus fragmented the contents of the file in the following way. Each line in the file is split into three or more strings separated only by spaces. Each line is fragmented within a line only, that is, all parts of a particular line are in the same line of the file and do not need to be searched elsewhere in the file. The only problem is that the individual parts of the line, into which the original line is divided, overlap in a certain number of characters (always at least one character). Your task is to write a program that will reassemble the fragmented lines of an individual file back into their original form. In doing so, it is necessary to find parts that match each other as closely as possible. Several remaining parts may match the end (or beginning) of a certain part, but only those two that match in the largest number of characters are folded together. But in order not to make the task too difficult, the first part of each individual line will always be in the first place in the line.
We have parts “110”, “01123”, “1011”. Both the beginning of the second part and the beginning of the first part coincide with the end of the third part. The second part matches in three characters, and the first in two, so the third part is finally combined with the second part in the string “101123”. The first part finally matches the beginning of the combined part in two characters and we get the final string “1101123”.
The file containing the data will be called “FileA.txt”. Your program should read the file and put the lines together accordingly. The final solution should be written in a new file called “FileB.txt”.
import java.util.*;
import java.io.*;
public class DomacaNaloga2
{
public static void main (String[] args)
{
String imeDatoteke = "DatotekaA.txt";
try
{
ArrayList<String> vrstice = vrniArray(imeDatoteke);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void preberiDatoteko (String imeDatoteke) throws Exception
{
String ime = imeDatoteke;
FileReader fr = new FileReader(ime);
BufferedReader dat = new BufferedReader(fr);
while(dat.ready())
{
System.out.println(dat.readLine());
}
dat.close();
}
public static ArrayList<String> vrniArray (String imeDatoteke) throws Exception
{
ArrayList<String> vrstice = new ArrayList<>();
String ime = imeDatoteke;
FileReader fr = new FileReader(ime);
BufferedReader dat = new BufferedReader(fr);
String vrstica;
while(dat.ready())
{
vrstica = dat.readLine();
vrstice.add(vrstica.trim());
}
dat.close();
return vrstice;
}
public static ArrayList<String> zdruziVrstice(ArrayList<string> vrstice)
{
ArraysList<String> zdruzeniNizi = new ArrayList<>();
for(int i = 0; i<vrstice.size(); i++)
{
String trenutna_vrstica = vrstice.get(i)
}
}
}
This is my code for now, i cannot seem to develop an alghorithm to solve this issue. All help would be usefull. I suppose i need to create a for loop of somekind to compare the objects in the array but to be honest i do not fully understand the task either and the proffesor is on vacation and the date to finish is in midnight so please help me guys.