Sunteți pe pagina 1din 2

PRACTICA EXAMEN 

 
import javax.swing.*; 
public class PROBLEMA1 { 
    public static void main(String[] args) {       
      String op; 
      GUIA p=null,a=null,u=null; 
      PROCESO pr=new PROCESO(); 
      do{ 
        op=JOptionPane.showInputDialog("M E N U\n1.‐INGRESAR DATOS\n2.‐VER DATOS\n3.‐SALIR\nELIJE UNA OPCION : "); 
        switch(op.charAt(0)){ 
          case '1':p=pr.ingreso(p,a,u);break; 
          case '2':pr.ver(p);break; 
        } 
      }while(op.charAt(0)!='3'); 
    } 

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 
class GUIA { 
  String no,di; 
  int fo; 
  GUIA pun; 

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
import javax.swing.*; 
class PROCESO { 
  GUIA ingreso(GUIA p,GUIA a,GUIA u) 
  { 
    String op; 
    do{ 
      if(p==null){ 
        p=new GUIA(); 
        p.no=JOptionPane.showInputDialog("Ingrese nombre : "+p.no); 
        p.di=JOptionPane.showInputDialog("Ingrese direccion : "+p.di); 
        p.fo=Integer.parseInt(JOptionPane.showInputDialog("Ingrese telefono : "+p.fo));   
        p.pun=null; 
        a=p; 
      } 
      else{//recorrido de la lista  
        GUIA x=null; 
        x=p; 
        while(x!=null){//realizamos el corridoç 
        a=x; 
        x=x.pun; 
        } 
      } 
     
      u=new GUIA(); 
        u.no=JOptionPane.showInputDialog("Ingrese nombre : "+u.no); 
        u.di=JOptionPane.showInputDialog("Ingrese direccion : "+u.di); 
        u.fo=Integer.parseInt(JOptionPane.showInputDialog("Ingrese telefono : "+u.fo)); 
        a.pun=u; 
        u.pun=null; 
      op=JOptionPane.showInputDialog("Para salir escriba FIN "); 
    } 
    while (op.compareTo("FIN")!=0); 
    return(p); 
  } 
  void ver (GUIA x){ 
    String cad=""; 
    while(x!=null){ 
      cad=cad+"NOMBRE = "+x.no+"\nDIRECCION = "+x.di+"\nTELEFONO = "+x.fo+"\n‐\n"; 
      x=x.pun; 
    } 
    JOptionPane.showConfirmDialog(null,cad); 
  } 

 
import javax.swing.*; 
import java.io.*; 
public class PROBLEMA2 {     
    public static void main(String[] args)throws IOException  {  
      String OP; 
      int op; 
      PROCESO PRO=new PROCESO(); 
    do{ 
    OP=JOptionPane.showInputDialog("MENU\n1)Vender\n2)Mostrar\n3)Salir"); 
      op=Integer.parseInt(OP); 
      switch(op){ 
        case 1:PRO.vender();break; 
        case 2:PRO.mostrar();break; 
        } 
      }while(op!=3); 
    } 
}import  java.io.*; 
import javax.swing.*; 
class PROCESO { 
  RandomAccessFile R; 
  String Producto,op,cad=""; 
  double  Precio; 
  public void abrir()throws  IOException{ 
    R=new RandomAccessFile("D:/tienda.txt","rw"); 
  } 
  void vender()throws IOException{ 
    do{ 
    abrir();  
    Producto=JOptionPane.showInputDialog("producto = "); 
      Precio=Double.parseDouble(JOptionPane.showInputDialog("Precio = ")); 
      Producto=(Producto+cad).substring(0,20);   
        R.seek(R.length()); 
        R.writeChars(Producto); 
        R.writeDouble(Precio); 
        op=JOptionPane.showInputDialog("Ingrese FIN para terminar = "); 
    }while(op.compareTo("FIN")!=0); 
    R.close(); 
  } 
void mostrar()throws IOException{ 
  abrir(); 
  String reg=""; 
  long tam; 
  tam=R.length();   
  for (int i=0;i<tam;i++){ 
    R.seek(72*i); 
    Producto=""; 
    for(int j=0;j<20;j++){ 
    Producto=Producto+R.readChar(); 
    } 
    Precio=R.readDouble(); 
    } 
    reg=reg+"PRODUCTO: "+Producto+"\nPrecio: "+Precio; 
    JOptionPane.showMessageDialog(null,"VENDIDOS"+reg); 
    R.close();}} 

S-ar putea să vă placă și