1
I’m having trouble in the case 5, where I have to delete vector elements, can anyone help? I’m starting programming now.
import javax.swing.*;
public class Gere {
public static void main (String [] arg) {
Professor Pr[];
Pr = new Professor [20];
int Matri = 0;
int Cont = -1;
int Menu = 0;
do { Menu = Integer.parseInt(JOptionPane.showInputDialog("\n1 = Inserir. \n2 = Imprimir. \n3 = Buscar por matricula. \n4 = Buscar por nome. \n5 = Excluir. \n6 = Sair."));
switch (Menu) {
case 1: {
JOptionPane.showMessageDialog(null,"O menu escolhido foi 1 = Inserir.");
Cont ++;
Pr[Cont] = new Professor();
Pr[Cont].setMatricula(Integer.parseInt(JOptionPane.showInputDialog("Informe a Matricula")));
Pr[Cont].setNome(JOptionPane.showInputDialog("Informe o Nome"));
Pr[Cont].setSalario(Integer.parseInt(JOptionPane.showInputDialog("Informe o Salario")));
Pr[Cont].setMateria(JOptionPane.showInputDialog("Informe a Materia"));
break;
}
case 2: {
JOptionPane.showMessageDialog(null,"O menu escolhido foi 2 = Imprimir.");
for (int i = 0; i <=Cont; i++) {
JOptionPane.showMessageDialog(null,"\n Matricula:" + Pr[i].getMatricula() +
"\n Nome:" + Pr[i].getNome() +
"\n Salario:" + Pr[i].getSalario() +
"\n Materia:" + Pr[i].getMateria() );
}
break;
}
case 3: {
JOptionPane.showMessageDialog(null,"O menu escolhido foi 3 = Buscar por matricula.");
Matri = Integer.parseInt(JOptionPane.showInputDialog("\n Digite a matricula"));
for ( int e =0; e != Matri; e++) {
if (Matri == Pr[e].getMatricula() ) {
JOptionPane.showMessageDialog(null, "\n Matricula:" + Pr[e].getMatricula() +
"\n Nome:" + Pr[e].getNome() +
"\n Salario:" + Pr[e].getSalario() +
"\n Materia:" + Pr[e].getMateria() );
}
}
break;
}
case 4: {
JOptionPane.showMessageDialog(null,"O menu escolhido foi 4 = Buscar por Nome.");
String Nom = JOptionPane.showInputDialog("\n Digite o Nome");
for ( int o=0; o <Cont ; o++) {
if (Nom.equals(Pr[o].getNome()) ) {
JOptionPane.showMessageDialog(null, "\n Matricula:" + Pr[o].getMatricula() +
"\n Nome:" + Pr[o].getNome() +
"\n Salario:" + Pr[o].getSalario() +
"\n Materia:" + Pr[o].getMateria() );
}
}
break;
}
case 5: {
int remover=0;
int Matri2 =0;
JOptionPane.showMessageDialog(null,"O menu escolhido foi 5 = Excluir.");
Matri2 = Integer.parseInt(JOptionPane.showInputDialog("\n Digite a matricula"));
for ( int u=0; u < Matri ; u++) {
if (Matri2 == remover(Pr[u].getMatricula()) ) {
}
}
break;
}
}
} while (Menu != 6);
}
}
Instead of using vector, why don’t you use one
List. It is much easier to manipulate objects in it, especially when talking about removal– EduardoFernandes
Go he wants to understand still the functioning of vectors...
– Aline