Java 什么是拯救这一切的最好方法?(保存应用程序生成的数据)

Java 什么是拯救这一切的最好方法?(保存应用程序生成的数据),java,database,file,Java,Database,File,我有这个代码,我想保存生成的数据,但我不知道如何保存,一个数据库?档案?我是否需要尝试代码中的每一项并重新开始 我来自巴西,所以变量和字符串都是葡萄牙语的,但我想编码的方法是通用的,所以任何改进代码的技巧都会很棒,我还没有完成,但这不是问题 package sistema_academico; import javax.swing.JOptionPane; public class Sistema_Academico { static Aluno Aluno[] = new Alun

我有这个代码,我想保存生成的数据,但我不知道如何保存,一个数据库?档案?我是否需要尝试代码中的每一项并重新开始

我来自巴西,所以变量和字符串都是葡萄牙语的,但我想编码的方法是通用的,所以任何改进代码的技巧都会很棒,我还没有完成,但这不是问题

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 < 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 < 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
package-sistema_-academico;
导入javax.swing.JOptionPane;
公立学院
{
静态Aluno Aluno[]=新Aluno[100];
静态教授[]=新教授[100];
静态int=0;
静态int-idP=0;
公共静态void main(字符串[]args)
{
布尔值bSair=true;
做
{
int-nOption=0;
字符串sEntrada=“”;
字符串sConcatenar=“”;
尝试
{
nOption=Integer.parseInt(JOptionPane.showInputDialog(“0-Sair\n”)+
“1-地籍编号\n”+
“2-地籍教授\n”+
“3-Pesquisar Aluno\n”+
“4-佩斯奎萨尔教授\n”+
“5-Alterar Aluno\n”+
“6-Alterar Professor\n”+
“7-排除Aluno\n”+
“8-不包括教授”);
}
捕获(异常编号格式)
{
}
开关(nOption)
{           
案例1:JOptionPane.showMessageDialog(null,“地籍Aluno”);
sEntrada=“”;
sConcatenar=“”;
sEntrada=JOptionPane.showInputDialog(“Nome:”)+“”;
sConcatenar=sEntrada;
sEntrada=JOptionPane.showInputDialog(“Endereço:”)+“”;
sConcatenar+=sEntrada;
sEntrada=JOptionPane.showInputDialog(“光标:)+“ux0”;
sConcatenar+=sEntrada;
sEntrada=JOptionPane.showInputDialog(“RA:”)+“uxAE”;
sConcatenar+=sEntrada;
地籍(斯肯卡泰纳);
打破
案例2:JOptionPane.showMessageDialog(null,“地籍教授”);
sEntrada=“”;
sConcatenar=“”;
sEntrada=JOptionPane.showInputDialog(“Nome:”)+“”;
sConcatenar=sEntrada;
sEntrada=JOptionPane.showInputDialog(“Endereço:”)+“”;
sConcatenar+=sEntrada;
sEntrada=JOptionPane.showInputDialog(“光标:)+“ux0”;
sConcatenar+=sEntrada;
sEntrada=JOptionPane.showInputDialog(“注册表:”)+“”;
sConcatenar+=sEntrada;
sEntrada=JOptionPane.showInputDialog(“材料:)+“ux0”;
sConcatenar+=sEntrada;
地籍测量员(sConcatenar);
打破
案例3:JOptionPane.showMessageDialog(null,“Pesquisar Aluno”);
sEntrada=“”;
sEntrada=JOptionPane.showInputDialog(“Pesquisar RA:”);
showMessageDialog(null,PesquisarAluno(sEntrada));
打破
案例4:JOptionPane.showMessageDialog(null,“Pesquisar教授”);
sEntrada=“”;
sEntrada=JOptionPane.showInputDialog(“Pesquisar注册表:”);
showMessageDialog(null,PesquisarProfessor(sEntrada));
打破
案例5:JOptionPane.showMessageDialog(null,“Alterar Aluno”);
打破
案例6:JOptionPane.showMessageDialog(null,“Alterar Professor”);
打破
案例7:JOptionPane.showMessageDialog(null,“Excluir Aluno”);
打破
案例8:JOptionPane.showMessageDialog(null,“排除教授”);
打破
案例0:
bSair=false;
打破
违约:
showMessageDialog(null,“Opço Invalida”);
打破
}
}while(bSair);
}//梅托多校长
公共静态无效地籍(字符串Al)
{   
idA++;
字符串数组[]=Al.split(“”);
Aluno[idA]=新的Aluno();
Aluno[idA].setNome(数组[0]);
Aluno[idA].setEndereco(数组[1]);
Aluno[idA].setCurso(数组[2]);
Aluno[idA].setRA(数组[3]);
}
公共静态无效地籍记录器(字符串Pf)
{
idP++;
字符串数组[]=Pf.split(“”);
教授[idP]=新教授();
[idP]教授.塞特诺姆(数组[0]);
[idP]教授.setEndereco(数组[1]);
[idP]教授.setCurso(数组[2]);
[idP]教授.setRegistro(数组[3]);
[idP]教授,setMateria(数组[4]);
}
公共静态字符串PesquisarAluno(字符串RA)
{
for(int i=0;i