Boa tarde pessoa,
Sou novo aqui e estou com um probleminha, estou fazendo um trabalho da faculdade, onde eu preciso ordenar alguns dados de um txt em bubble sort, segue as classes já criadas;
Desde já grato a todos.
public class Detritos {
private int cod, lancamento, reentrada;
private String nome, velocidade, classe, estado;
public Detritos() {
}
public Detritos(int cod, int lancamento, int reentrada, String nome, String velocidade, String classe,
String estado) {
this.cod = cod;
this.lancamento = lancamento;
this.reentrada = reentrada;
this.nome = nome;
this.velocidade = velocidade;
this.classe = classe;
this.estado = estado;
}
public int getCod() {
return cod;
}
public void setCod(int cod) {
this.cod = cod;
}
public int getLancamento() {
return lancamento;
}
public void setLancamento(int lancamento) {
this.lancamento = lancamento;
}
public int getReentrada() {
return reentrada;
}
public void setReentrada(int reentrada) {
this.reentrada = reentrada;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getVelocidade() {
return velocidade;
}
public void setVelocidade(String velocidade) {
this.velocidade = velocidade;
}
public String getClasse() {
return classe;
}
public void setClasse(String classe) {
this.classe = classe;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
}
import java.awt.Container;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class ArquivoTxT {
public String Cod, Nome, Classe, Estado, Lancamento, Reentrada, Velocidade;
public ArquivoTxT ler(String path) {
try {
BufferedReader br = new BufferedReader(new FileReader(path + "/" + Cod + "txt"));
Cod = br.readLine();
Nome = br.readLine();
Classe = br.readLine();
Estado = br.readLine();
Lancamento = br.readLine();
Reentrada = br.readLine();
Velocidade = br.readLine();
br.close();
return this;
} catch (IOException erro) {
return null;
}
}
public void Cadastrar(Detritos detrito) throws IOException {
if (checarExistente(detrito)) {
JOptionPane.showMessageDialog(null, "COD já existente");
} else {
try {
BufferedWriter br = new BufferedWriter(new FileWriter("c:\\APS\\ARQUIVOS TXT\\APSTXT.txt", true));
br.write(detrito.getCod() + ",");
br.write(detrito.getNome() + ",");
br.write(detrito.getClasse() + ",");
br.write(detrito.getEstado() + ",");
br.write(detrito.getLancamento() + ",");
br.write(detrito.getReentrada() + ",");
br.write(detrito.getVelocidade());
br.newLine();
br.close();
} catch (IOException erro) {
JOptionPane.showMessageDialog(null, "Erro para gravar");
}
}
}
public static void main(String[] args) {
File dir = new File("c:/APS");
if (!dir.exists()) {
dir.mkdir();
}
dir = new File("c:/APS/ARQUIVOS TXT");
if (!dir.exists())
;
{
dir.mkdir();
}
System.out.println("Final do processo de criação");
ArquivoTxT teste = new ArquivoTxT();
}
public ArrayList<Detritos> txt() throws IOException {
ArrayList<Detritos> dados = new ArrayList<Detritos>();
try {
FileInputStream arquivo = new FileInputStream("c:/APS/ARQUIVOS TXT/APSTXT.txt");
InputStreamReader input = new InputStreamReader(arquivo);
BufferedReader br = new BufferedReader(input);
String dado[];
while (br.ready()) {
try {
dado = br.readLine().split(",");
int cod = Integer.parseInt(dado[0]);
String nome = dado[1];
String classe = dado[2];
String estado = dado[3];
int lancamento = Integer.parseInt(dado[4]);
int reentrada = Integer.parseInt(dado[5]);
String velocidade = dado[6];
dados.add(new Detritos(cod, lancamento, reentrada, nome, velocidade, classe, estado));
} catch (Exception e) {
continue;
}
}
br.close();
} catch (IOException ex) {
System.out.println("Erro para ler arquivo");
ex.printStackTrace();
} finally {
}
return dados;
}