Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class EstadisticasFacturas {
- public static Scanner scTeclado = new Scanner (System.in);
- public static void main(String[] args) {
- importarFichero();
- }
- public static void importarFichero (){
- System.out.println("===============");
- System.out.println("Introduzca el nombre del fichero de facturas");
- String nombreFichero = scTeclado.nextLine ();
- try {
- Scanner sc = new Scanner (new File (nombreFichero));
- //Desechamos la cabecera del fichero
- sc.nextLine();//no recogemos esta linea pero se ha leido igualmente
- sc.nextLine();
- sc.nextLine();
- while (sc.hasNextLine()){
- }
- String lineaCliente = sc.nextLine ();
- String [] datosCliente =lineaCliente.split(",");
- String nombreCliente = datosCliente [1];
- System.out.println(nombreCliente);
- double totalFacturacion = 0;
- //leemos la siguiente línea y damos por sentado que es un cliente
- String lineaFactura = sc.nextLine();
- //Este bucle lee la linea a linea hasta que encuentre un separador
- while (!lineaFactura.startsWith("-")){
- String []datosFactura = lineaFactura.split(",");
- String totalStr = datosFactura [2];
- double total = Double.parseDouble(totalStr); // Esta linea transforma
- double total2 = Double.parseDouble (datosFactura [2]);
- totalFacturacion = totalFacturacion + total;
- lineaFactura = sc.nextLine();
- }
- System.out.println(totalFacturacion);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }}
Add Comment
Please, Sign In to add comment