Guest User

Untitled

a guest
Jan 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class EstadisticasFacturas {
  7.  
  8. public static Scanner scTeclado = new Scanner (System.in);
  9.  
  10.  
  11. public static void main(String[] args) {
  12.  
  13. importarFichero();
  14.  
  15. }
  16.  
  17.  
  18. public static void importarFichero (){
  19.  
  20. System.out.println("===============");
  21. System.out.println("Introduzca el nombre del fichero de facturas");
  22. String nombreFichero = scTeclado.nextLine ();
  23.  
  24. try {
  25. Scanner sc = new Scanner (new File (nombreFichero));
  26.  
  27. //Desechamos la cabecera del fichero
  28. sc.nextLine();//no recogemos esta linea pero se ha leido igualmente
  29. sc.nextLine();
  30. sc.nextLine();
  31.  
  32. while (sc.hasNextLine()){
  33.  
  34. }
  35. String lineaCliente = sc.nextLine ();
  36. String [] datosCliente =lineaCliente.split(",");
  37.  
  38. String nombreCliente = datosCliente [1];
  39. System.out.println(nombreCliente);
  40.  
  41. double totalFacturacion = 0;
  42. //leemos la siguiente línea y damos por sentado que es un cliente
  43. String lineaFactura = sc.nextLine();
  44. //Este bucle lee la linea a linea hasta que encuentre un separador
  45. while (!lineaFactura.startsWith("-")){
  46. String []datosFactura = lineaFactura.split(",");
  47. String totalStr = datosFactura [2];
  48. double total = Double.parseDouble(totalStr); // Esta linea transforma
  49. double total2 = Double.parseDouble (datosFactura [2]);
  50.  
  51.  
  52. totalFacturacion = totalFacturacion + total;
  53.  
  54.  
  55. lineaFactura = sc.nextLine();
  56. }
  57. System.out.println(totalFacturacion);
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. } catch (FileNotFoundException e) {
  65. e.printStackTrace();
  66. }
  67.  
  68. }}
Add Comment
Please, Sign In to add comment