I'm writing a school project: a car rent system.
So far we can register a car with a model, color, etc... and an avaible character (Y/N). We are using a .txt file to save the car atributes, and another .txt file to save the clients atributes.
To rent a car we select a client, a car, then we get an unique atribute from each one (the license plate and id), save it to another .txt file, and in the car .txt file we have to change the avaible character from Y to N.
We are using an interface to do this, and we have a table with the list of clients and cars registred. First we select a client, click NEXT, then select a car and click RENT. The avaible character in the table changes from Y to N but I can't make it to save in the cars .txt file also.
I'd like some help with this
This is the code on the "register the car" window
public void persistir(){
File file = new File("carros.txt");
for(int i=0; i<qtd; i++){
try {
Veiculo carro = carros[i];
//verifica se o arquivo já existe e escreve no final do mesmo
FileWriter fileWriter = new FileWriter("carros.txt", true);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(carro.getMarca() + ";" + carro.getModelo() + ";" + carro.getCor() + ";" + carro.getCategoria() + ";" + carro.getAno() + ";" + carro.getPlaca() + ";" + carro.getDisponivel() + ";");
bufferedWriter.newLine();
bufferedWriter.close();
} catch (HeadlessException | IOException e) {
System.out.println("Erro: " + e);
}
}
}
and this is the code on the RENT button
private void finalizarActionPerformed(java.awt.event.ActionEvent evt) {
int linha = tabVeiculos2.getSelectedRow();
GPLACA = (tabVeiculos2.getValueAt(linha, 5)).toString();
tabVeiculos2.setValueAt("N", linha, 6);
Alugar(GRG,GPLACA);
JOptionPane.showMessageDialog(null, "Locação Realizada com sucesso!");
System.out.println(GPLACA);
this.dispose();
}
let me know if you need help translating something, thanks.
Edit: since you all think I just want to get my work done, I'm not. I can't make any progress since this.
Volkswagen;Gol;Preto;Popular;2016;AAA0000;Y; Ford;Fiesta;Prata;Popular;2011;BBB1111;Y;
This is in the cars.txt file and I want to know how I change the Y to N.