I have a question to remove an object from a list in a job. I have an automotive class:
public class Automovel {
String marca;
String modelo;
String preco;
Automovel(String marca, String modelo, String preco) {
this.marca = marca;
this.modelo = modelo;
this.preco = preco;
}
// ja esta como geter e seters
I also have a utility class that implements this class:
package metodista.ads.carro;
import java.util.ArrayList;
/**
*
* @author Luiz Ricardo
*/
public class Concessionaria {
public Concessionaria() {
}
ArrayList<Automovel> carros = new ArrayList<>();
//O método adicionaVeiculo deverá adicionar um veículo ao estoque (atributo listaAutomoveis).
public void adicionaVeiculo(Automovel automovel){
carros.add(automovel);
}
// O método vendaVeiculo remove um veículo do estoque.
public void vendaVeiculo(Automovel automovel){
carros.remove(automovel);
}
//O método consultaEstoqueVeiculo devolve os veículos em estoque.
public String consultaEstoqueVeiculo(){
return carros.size()+"";
}
}
//
My main class has a screen for user data entry, my doubt is in the method to remove an Auto object, I have a button that when clicked would need to take an automobile object out of stock, but it does not work:
private void btVenderActionPerformed(java.awt.event.ActionEvent evt) {
// construtor concessionaria
Concessionaria con = new Concessionaria();
String marca = tfMarca.getText();
String modelo = tfModelo.getText();
String preco = tfPreco.getText();
Automovel auto2 = new Automovel(marca, modelo, preco);
con.vendaVeiculo(auto2);
My main class has a screen for user data entry, my question is in the VehicleSale method to remove an Automotive object.