jueves, 27 de octubre de 2011

BoletaSupermercado - Objetos intermediarios

Clase principal

 1 package boletaventa213;
 2 
 3         import java.io.BufferedReader;
 4         import java.io.InputStreamReader;
 5         import java.io.IOException;
 6         import java.util.ArrayList;
 7 
 8 public class BoletaVenta213 
 9 {    
10     public static ArrayList<detalleBoleta> detabol = new ArrayList();
11     public static void main(String[] args) throws IOException
12     {    
13         String producto;
14         int codigo; 
15         int precio;
16         int cantidad;
17         String op;
18         boletas bole = new boletas(1,"21-12-2011");
19         
20         BufferedReader tex = new BufferedReader(new InputStreamReader(System.in));
21         System.out.println("-.SUPERMERCADOS LA TIJUANA.-");
22         
23         do{
24             System.out.print("Ingrese código del producto: ");
25             codigo=Integer.parseInt(tex.readLine());           
26             
27             System.out.print("Ingrese nombre del producto: ");
28             producto=tex.readLine();
29             
30             System.out.print("Ingrese precio del producto: ");
31             precio=Integer.parseInt(tex.readLine());
32             System.out.print("Ingrese cantidad del producto: ");
33             cantidad=Integer.parseInt(tex.readLine());
34             System.out.println("");
35             
36             System.out.print("desea agregar mas productos? s/n : ");
37             op=tex.readLine();
38             System.out.println("");
39               subAgregaProducto(codigo,producto,precio, bole, cantidad);
40             
41             
42         }while(op.equals("s"));
43         
44         
45         int i;
46 
47         
48         System.out.println("DETALLE DE LA BOLETA : ");  
49         
50         System.out.println(detabol.get(0).getBoleta().numero);
51         System.out.println(detabol.get(0).getBoleta().fecha);
52         System.out.println("Código   Nombre     PrecioUnitario      Cantidad         Precio   ");
53         for (i=0;i<detabol.size();i++)
54         {
55 
56             System.out.print(detabol.get(i).getProducto().codigo+"        ");
57             System.out.print(" ");
58             System.out.print(detabol.get(i).getProducto().Nombre+"        ");
59             System.out.print(" ");
60             System.out.print(detabol.get(i).getProducto().precioUnitario+"                ");
61             System.out.print(" ");
62             System.out.print(detabol.get(i).cantidad+"              "); 
63             System.out.print(" ");
64             System.out.print(detabol.get(i).getProducto().precioUnitario*
65                              detabol.get(i).cantidad); 
66             System.out.println("");
67         }
68     }  
69     
70     public static void subAgregaProducto(int codigo, String nombre,
71                                          int precio,boletas bole,
72                                          int cantidad)
73     {
74         productos prod = new productos(codigo,nombre,precio);
75         detabol.add(new detalleBoleta(bole, prod, cantidad));
76         
77     }
78 }



Clase productos
 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 package boletaventa213;
 6 
 7 /**
 8  *
 9  * @author Luis Bravo Yanes
10  */
11 public class productos 
12 {
13     int codigo;
14     String Nombre;
15     int precioUnitario;
16 
17     public productos(int codigo, String Nombre, int precioUnitario) {
18         this.codigo = codigo;
19         this.Nombre = Nombre;
20         this.precioUnitario = precioUnitario;
21     }
22 
23     public String getNombre() {
24         return Nombre;
25     }
26 
27     public void setNombre(String Nombre) {
28         this.Nombre = Nombre;
29     }
30 
31     public int getCodigo() {
32         return codigo;
33     }
34 
35     public void setCodigo(int codigo) {
36         this.codigo = codigo;
37     }
38 
39     public float getPrecioUnitario() {
40         return precioUnitario;
41     }
42 
43     public void setPrecioUnitario(int precioUnitario) {
44         this.precioUnitario = precioUnitario;
45     }
46     
47     
48 }

Clase Boletas
 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 package boletaventa213;
 6 
 7 /**
 8  *
 9  * @author Luis Bravo Yanes
10  */
11 public class boletas 
12 {
13     int numero;
14     String fecha;
15 
16     public boletas(int numero, String fecha) {
17         this.numero = numero;
18         this.fecha = fecha;
19     }
20 
21     public String getFecha() {
22         return fecha;
23     }
24 
25     public void setFecha(String fecha) {
26         this.fecha = fecha;
27     }
28 
29     public int getNumero() {
30         return numero;
31     }
32 
33     public void setNumero(int numero) {
34         this.numero = numero;
35     }
36     
37     
38     
39 }

Clase detalleBoleta

 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 package boletaventa213;
 6 
 7 /**
 8  *
 9  * @author Luis Bravo Yanes
10  */
11 public class detalleBoleta 
12 {
13     private boletas boleta;
14     private productos producto;
15     int cantidad;
16 
17     public detalleBoleta(boletas boleta, productos producto, int cantidad) {
18         this.boleta = boleta;
19         this.producto = producto;
20         this.cantidad = cantidad;
21     }
22 
23     public boletas getBoleta() {
24         return boleta;
25     }
26 
27     public void setBoleta(boletas boleta) {
28         this.boleta = boleta;
29     }
30 
31     public int getCantidad() {
32         return cantidad;
33     }
34 
35     public void setCantidad(int cantidad) {
36         this.cantidad = cantidad;
37     }
38 
39     public productos getProducto() {
40         return producto;
41     }
42 
43     public void setProducto(productos producto) {
44         this.producto = producto;
45     }
46     
47     
48     
49 }

No hay comentarios:

Publicar un comentario