sábado, 8 de octubre de 2016

Registro Y Control En Java

Registro Y Control En Java

Código De Ingresar Datos,Buscar Datos,Mostrar Datos,Modificar Datos,y Eliminar Datos,El De Restaurar No Funciona Bien.

Clase Principal
package arrobj;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;


public class ArrObj {
 
    int contEst=0, cod=1; //variable llevar control usuarios ingresados
 
    userBanc estudiante [] = new userBanc[100]; //creando el arreglo de objetos (clase userBanc)
    userBanc papelerauser [] = new userBanc[100];
 
    public ArrObj(){ //constructor de la clase ArrObj
        menuPrincipal();
    }
 
    public void menuPrincipal(){
     
        String op;
        boolean s=true;

        do{
            op = JOptionPane.showInputDialog("\nREGISTRO Y CONTROL"
                                            + "\n 1.INGRESAR"
                                            + "\n 2.MOSTRAR"
                                            + "\n 3.BUSCAR "
                                            + "\n 4.MODIFICAR"
                                            + "\n 5.ELIMINAR"
                                            + "\n 6.RESTAURAR"
                                            + "\n 7.SALIR "  ) ;
            if(op!=null && !op.equals("")){

                switch(op){
                    case "1":
                        ingresar();
                        break;
                    case "2":
                        mostrar();
                        break;
                    case "3":
                        buscar();
                        break;
                    case "4":
                        modificar();
                        break;
                    case "5":
                        eliminar();
                        break;
                    case "6":
                        restaurar();
                        break;
                    case "7":
                         s=false;
                        break;
                          default:
                        JOptionPane.showMessageDialog(null,"Numero no Valido ","ERROR",JOptionPane.ERROR_MESSAGE) ;
                     }            
                }
         
        }while(s);
    }

    public void ingresar(){      

     
        String nom_est,cod_est,mat_est;
        double n1,n2,n3;      

        cod_est = JOptionPane.showInputDialog(null, "Ingrese el codido del estudiante ");
        nom_est = JOptionPane.showInputDialog(null, "Ingrese el nombre del estudiante: ");
        mat_est =(JOptionPane.showInputDialog(null, "Ingrese la materia del estudiante: ")) ;
        n1 = Double.parseDouble(JOptionPane.showInputDialog(null, "Ingrese nota 1: "));
        n2 = Double.parseDouble(JOptionPane.showInputDialog(null, "Ingrese nota 2: "));
        n3 = Double.parseDouble(JOptionPane.showInputDialog(null, "Ingrese nota 3: "));
     

        userBanc temp = new userBanc();
     
        temp.setCod(cod);
        temp.setCod_est(cod_est);
        temp.setNom_est(nom_est);
        temp.setMat_est(mat_est);
        temp.setN1(n1);
        temp.setN2(n2);
        temp.setN3(n3);
     
        temp.calcularDef();
     
        estudiante[contEst] = temp;
     
        if(estudiante[contEst].getDef()>=3){
         estudiante[contEst].setEstado("Gano");
         }else{
         estudiante[contEst].setEstado("Perdio");
         };
       
         JOptionPane.showMessageDialog(null, "SE REGISTRO EL ESTUDIANTE CORRECTAMENTE");
       
        contEst++;
        cod++;    
    }

    public void mostrar(){
        JTextArea salida=new JTextArea(25,40);
         JScrollPane desli=new JScrollPane(salida);
     salida.setText("codigo\tNombre\tMateria\tNota 1\tNota 2\tNota 3\tDefinitiva\tEstado\n");
         for (int i = 0; i < contEst; i++) {
          salida.append(estudiante[i].getCod_est()+"\t"+estudiante[i].getNom_est()+
                        "\t"+estudiante[i].getMat_est()+"\t"+estudiante[i].getN1()+"\t"
                        +estudiante[i].getN2()+"\t"+estudiante[i].getN3()+
                        "\t"+estudiante[i].getDef()+"\t"+estudiante[i].getEstado()+"\n");
         }
         JOptionPane.showMessageDialog(null,desli);
     
    }

    public void buscar(){
      String ax;
    int c;
    ax=JOptionPane.showInputDialog("digitar codigo a buscar");
    if(ax!=null && !ax.equals("")){
    c=Integer.parseInt(ax);
    if(contEst!=0){
    for(int i=0;i<contEst;i++){
    if(Integer.parseInt (estudiante[i].getCod_est())==c){
    ax="";
    ax+="codigo:" +estudiante[i].getCod_est()+"\n"
       +"nombre:" +estudiante[i].getNom_est()+"\n"
       +"materia:" +estudiante[i].getMat_est()+"\n"
       +"nota1:"+estudiante[i].getN1()+"\n"
       +"nota2:"+estudiante[i].getN2()+"\n"
       +"nota3:"+estudiante[i].getN3()+"\n"
       +"definitiva:"+estudiante[i].getDef()+"\n"
       +"estado:"+estudiante[i].getEstado()+"\n";

     
   
    }
    }
        }else{ax="no se ha encontrado el estudiante";
    }
   
    }
    JOptionPane.showMessageDialog(null,ax);
     
    }
   
  public void modificar(){
   
      String cod = JOptionPane.showInputDialog("Digite el codigo del estudiante a modificar ");
       
      for(int i=0;i<this.estudiante.length;i++) {
       
       if(estudiante[i].getCod() == Integer.parseInt(cod)){
     
       String op = JOptionPane.showInputDialog(null," DATOS DEL USUARIO \n\n"
                     +"\t   Codigo :" +estudiante[i].getCod_est()+"\n"
                     +"\t1. Nombre :" +estudiante[i].getNom_est()+"\n"
                    +"\t2. Materia :" +estudiante[i].getMat_est()+"\n"
        +"\t3. Nota1 :"+estudiante[i].getN1()+"\n"
        +"\t4. Nota2 :"+estudiante[i].getN2()+"\n"
        +"\t5. Nota3 :"+estudiante[i].getN3()+"\n"
        +"\t   Definitiva :"+estudiante[i].getDef()+"\n"
        +"\t   Estado :"+estudiante[i].getEstado()+"\n"
                     +"\t6. Atras \n\n"
                     +" Que dato desea modificar ?");
           
             switch(op){
                 case "1" :
                     String nNombre = JOptionPane.showInputDialog(null," Nuevo Nombre \n");
                     estudiante[i].setNom_est(nNombre);
                     JOptionPane.showMessageDialog(null," Dato modificado con exito...");
                     menuPrincipal();
                 break;
                 case "2" :
                     String nMateria = JOptionPane.showInputDialog(null," Nueva Materia \n");
                     estudiante[i].setMat_est(nMateria);
                     JOptionPane.showMessageDialog(null," Dato modificado con exito...");
                     menuPrincipal();
                 break;
                 case "3" :
                     String nNota1 = JOptionPane.showInputDialog(null," Nueva Nota1 \n");
                     estudiante[i].setN1(Double.parseDouble(nNota1));
                     JOptionPane.showMessageDialog(null," Dato modificado con exito...");
                     menuPrincipal();
                 break;
                 case "4" :
                     String nNota2 = JOptionPane.showInputDialog(null," Nueva Nota2 \n");
                     estudiante[i].setN2(Double.parseDouble(nNota2));
                     JOptionPane.showMessageDialog(null," Dato modificado con exito...");
                     menuPrincipal();
                 break;
                 case "5" :
                     String nNota3 = JOptionPane.showInputDialog(null," Nueva Nota3 \n");
                     estudiante[i].setN3(Double.parseDouble(nNota3));
                     JOptionPane.showMessageDialog(null," Dato modificado con exito...");
                     menuPrincipal();
                 break;
                 case "6":
                     menuPrincipal();
                 break;
                 default:
                     JOptionPane.showMessageDialog(null," Opcion invalida.");
             }
          }else{
           JOptionPane.showMessageDialog(null," Este usuario no esta registrado.");
          }
       
      }
   
  }

  public void eliminar(){
      String cod = JOptionPane.showInputDialog("Digite el codigo del estudiante a eliminar ");
       
      for(int i=0;i<this.estudiante.length;i++) {
       
       if(estudiante[i].getCod() == Integer.parseInt(cod)){
         
           for (int j = 0; j == papelerauser.length ; j++) {
               if(estudiante[i] != papelerauser[j]){
                   papelerauser[j] = estudiante[i];
               }
           }
         
           estudiante[i].setCod(0);
           estudiante[i].setNom_est(null);
           estudiante[i].setMat_est(null);
           estudiante[i].setN1(0.0);
           estudiante[i].setN2(0.0);
           estudiante[i].setN3(0.0);
           estudiante[i].setDef(0.0);
           estudiante[i].setEstado(null);
         
          JOptionPane.showMessageDialog(null," Eliminado con exito.");
       
          menuPrincipal();
       
          }else{
           JOptionPane.showMessageDialog(null," Este usuario no esta registrado.");
          }
       
      }
   
  }

  public void restaurar(){
   
      JTextArea salida=new JTextArea(25,40);
      JScrollPane desli=new JScrollPane(salida);
   
      salida.setText(" CONTENIDO DE LA PAPELERA\n\n"
              + "codigo\tNombre\tMateria\tNota 1\tNota 2\tNota 33\tDefinitiva\tEstado\n");
   
         for(int i = 0; i == papelerauser.length; i++) {
          salida.append(papelerauser[i].getCod_est()+"\t"+papelerauser[i].getNom_est()+
                        "\t"+papelerauser[i].getMat_est()+"\t"+papelerauser[i].getN1()+"\t"
                        +papelerauser[i].getN2()+"\t"+papelerauser[i].getN3()+
                        "\t"+papelerauser[i].getDef()+"\t"+papelerauser[i].getEstado()+"\n");
         }
       
         JOptionPane.showMessageDialog(null,desli);
         menuPrincipal();
           
  }

    public static void main(String[] args) {
         try{

  JFrame.setDefaultLookAndFeelDecorated(true);
  JDialog.setDefaultLookAndFeelDecorated(true);
  UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
  UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
  UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");



}
catch (Exception e)
 {
  e.printStackTrace();
 }
        JFrame ventana=new JFrame();

        ArrObj w = new ArrObj(); //creacion del objeto w, llamado al constructor de la clase ArrObj
        System.exit(0);      
    }

    private String estudiante() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
- Clase Metodos Get y Set

package arrobj;

class userBanc {
    
    private int cod; 
    private String nom_est,cod_est,mat_est;
    private double n1,n2,n3,def;
    private String estado;

    public userBanc() {
    }

    public userBanc(int cod, String nom_est, String cod_est, String mat_est, double n1, double n2, double n3, double def, String estado) {
        this.cod = cod;
        this.nom_est = nom_est;
        this.cod_est = cod_est;
        this.mat_est = mat_est;
        this.n1 = n1;
        this.n2 = n2;
        this.n3 = n3;
        this.def = def;
        this.estado = estado;
    }

    public int getCod() {
        return cod;
    }

    public void setCod(int cod) {
        this.cod = cod;
    }

    public String getNom_est() {
        return nom_est;
    }

    public void setNom_est(String nom_est) {
        this.nom_est = nom_est;
    }

    public String getCod_est() {
        return cod_est;
    }

    public void setCod_est(String cod_est) {
        this.cod_est = cod_est;
    }

    public String getMat_est() {
        return mat_est;
    }

    public void setMat_est(String mat_est) {
        this.mat_est = mat_est;
    }

    public double getN1() {
        return n1;
    }

    public void setN1(double n1) {
        this.n1 = n1;
    }

    public double getN2() {
        return n2;
    }

    public void setN2(double n2) {
        this.n2 = n2;
    }

    public double getN3() {
        return n3;
    }

    public void setN3(double n3) {
        this.n3 = n3;
    }

    public double getDef() {
        return def;
    }

    public void setDef(double def) {
        this.def = def;
    }

    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }
    
    public double calcularDef(){
      
        this.def = this.n1*0.3+this.n2*0.3+this.n3*0.4;
     
        return this.def;
    }

   
}



0 comentarios:

Publicar un comentario