I'm trying to do an exercise where I have to use the ArrayList class and I can not find a way to do it. The statement of the exercise is as follows:
In a teletype terminal there is a backspace character that allows you to cancel the last character.
For example: If the backspace character is
/
, then the lineabc/d//e
will be interpreted asae
.There is also a null character that eliminates all the characters entered so far, suppose that character is
&
.Perform a method that, given a strip of completed characters with
*
(read from the file " Source.txt "), executes the indicated operations if it encounters the character/
or&
. You must finally print the resulting strip.
I pass the class Teletipo.java :
package terminal_teletipo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Teletipo {
int cont = 0;
private String secuencia;
File f = new File("D:\Proyectos Java\List_Interface\Fuente.txt");
ArrayList<Character> lista = new ArrayList<Character>();
public void File_Test() {
System.out.println("El archivo existe? : " + f.exists() + " ");
if (f.exists() == true) System.out.println("Direccion: " + f.getAbsolutePath());
else System.out.println("El archivo no existe");
}
public void setArrayList() throws FileNotFoundException, IOException {
FileReader r = new FileReader(f);
BufferedReader b = new BufferedReader(r);
secuencia = b.readLine();
System.out.println(secuencia);
for (int i = 0; i < secuencia.length(); i++) {
lista.add(secuencia.charAt(i));
}
}
}