Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/02/2013, 08:08
ambigus
 
Fecha de Ingreso: septiembre-2008
Mensajes: 221
Antigüedad: 16 años, 4 meses
Puntos: 1
¿Cómo sumar una lista de datos?

Hola este es mi código actual

Código Javascript:
Ver original
  1. package sucursales;
  2.  
  3.  
  4.  
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. public class Ventas {
  12.  
  13.     private BufferedReader  lector   = null;
  14.     private List<Integer>   venta    = null;
  15.     int                     option =      0;
  16.    
  17.     public void totalventas(){
  18.        
  19.         for ( int i=0; i<this.venta.size(); i++)
  20.         {
  21.             int suma = suma+venta.get(i);
  22.         }
  23.         System.out.println( "La suma total de ventas es" +suma);
  24.  
  25.     }
  26.    
  27.     public void registro() throws IOException
  28.     {
  29.        
  30.         lector = new BufferedReader(
  31.                 new InputStreamReader(System.in)
  32.               );
  33.  
  34.         System.out.println("Para finalizar el registro de ventas digite 9999");
  35.        
  36.         do
  37.         {
  38.            
  39.  
  40.            
  41.             this.venta = new ArrayList<Integer>();
  42.             System.out.println("Escriba el valor de la venta");
  43.             int j = Integer.parseInt(lector.readLine());
  44.             if (j != 9999 )
  45.             {
  46.                 venta.add(j);
  47.             }
  48.             else
  49.             {
  50.                 option = 9999;
  51.             }
  52.            
  53.            
  54.             switch(option)
  55.             {
  56.             case 1: break;
  57.             }
  58.         }while(option!=9999);
  59.        
  60.     }  
  61. }

No entiendo, ¿Porqué no me reconoce la variable suma?, ¿Está bien lo que estoy haciendo para sumar?

Espero una pronta respuesta.
Gracias de antemano.