Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to save this? (saving the data generated by an application)
    text
    copied!<p>I have this code, and i want to save the generated data, but i don't know how, A database? a file? do i need to chance everyting in the code and start over again?</p> <p>I'm from brazil, so the variables and Strings are in portuguese but i guess the way to code is Universal, So any Tips to improve the code will be awesome, i didn't finish yet but it is not a problem. </p> <pre><code>package sistema_academico; import javax.swing.JOptionPane; public class Sistema_Academico { static Aluno Aluno[] = new Aluno[100]; static Professor Professor[] = new Professor[100]; static int idA = 0; static int idP = 0; public static void main(String[] args) { boolean bSair = true; do { int nOption = 0; String sEntrada = ""; String sConcatenar = ""; try { nOption = Integer.parseInt(JOptionPane.showInputDialog("0 - Sair \n" + "1 - Cadastrar Aluno \n" + "2 - Cadastrar Professor \n" + "3 - Pesquisar Aluno \n" + "4 - Pesquisar Professor \n" + "5 - Alterar Aluno \n" + "6 - Alterar Professor \n" + "7 - Excluir Aluno \n" + "8 - Excluir Professor \n")); } catch(Exception NumberFormat) { } switch (nOption) { case 1: JOptionPane.showMessageDialog(null, "Cadastrar Aluno"); sEntrada = ""; sConcatenar = ""; sEntrada = JOptionPane.showInputDialog("Nome: ") + "_"; sConcatenar = sEntrada; sEntrada = JOptionPane.showInputDialog("Endereço: ") + "_"; sConcatenar += sEntrada; sEntrada = JOptionPane.showInputDialog("Curso: ") + "_"; sConcatenar += sEntrada; sEntrada = JOptionPane.showInputDialog("RA: ") + "_"; sConcatenar += sEntrada; CadastrarAluno(sConcatenar); break; case 2: JOptionPane.showMessageDialog(null, "Cadastrar Professor"); sEntrada = ""; sConcatenar = ""; sEntrada = JOptionPane.showInputDialog("Nome: ") + "_"; sConcatenar = sEntrada; sEntrada = JOptionPane.showInputDialog("Endereço: ") + "_"; sConcatenar += sEntrada; sEntrada = JOptionPane.showInputDialog("Curso: ") + "_"; sConcatenar += sEntrada; sEntrada = JOptionPane.showInputDialog("Registro: ") + "_"; sConcatenar += sEntrada; sEntrada = JOptionPane.showInputDialog("Materia: ") + "_"; sConcatenar += sEntrada; CadastrarProfessor(sConcatenar); break; case 3: JOptionPane.showMessageDialog(null, "Pesquisar Aluno"); sEntrada = ""; sEntrada = JOptionPane.showInputDialog("Pesquisar RA:"); JOptionPane.showMessageDialog(null, PesquisarAluno(sEntrada)); break; case 4: JOptionPane.showMessageDialog(null, "Pesquisar Professor"); sEntrada = ""; sEntrada = JOptionPane.showInputDialog("Pesquisar Registro:"); JOptionPane.showMessageDialog(null, PesquisarProfessor(sEntrada)); break; case 5: JOptionPane.showMessageDialog(null, "Alterar Aluno"); break; case 6: JOptionPane.showMessageDialog(null, "Alterar Professor"); break; case 7: JOptionPane.showMessageDialog(null, "Excluir Aluno"); break; case 8: JOptionPane.showMessageDialog(null, "Excluir Professor"); break; case 0: bSair = false; break; default: JOptionPane.showMessageDialog(null, "Opção Invalida"); break; } }while(bSair); }// Metodo Principal public static void CadastrarAluno(String Al) { idA++; String array[] = Al.split("_"); Aluno[idA] = new Aluno(); Aluno[idA].setNome(array[0]); Aluno[idA].setEndereco(array[1]); Aluno[idA].setCurso(array[2]); Aluno[idA].setRA(array[3]); } public static void CadastrarProfessor(String Pf) { idP++; String array[] = Pf.split("_"); Professor[idP] = new Professor(); Professor[idP].setNome(array[0]) ; Professor[idP].setEndereco(array[1]); Professor[idP].setCurso(array[2]); Professor[idP].setRegistro(array[3]); Professor[idP].setMateria(array[4]); } public static String PesquisarAluno(String RA) { for(int i = 0; i &lt; idA; i++) { if(Aluno[idA].getRA().equals(RA)) { return Aluno[idA].getNome(); } } return "RA não Cadastrado"; } public static String PesquisarProfessor(String RE) { for(int i = 0; i &lt; idP; i++) { if(Professor[idP].getRegistro().equals(RE)) { return Professor[idP].getNome(); } } return "Registro não Cadastrado"; } public static void AlterarAluno(String Al) { } public static void AlterarProfessor(String Pf) { } public static void ExcluirAluno(String Al) { } public static void ExcluirProfessor(String Pf) { } }// Classe Principal </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload