
import java.io.*;
import java.util.Scanner;


/**
 * This is a demo of File input and output here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class FileIODemo
{
    public static void main(String[] args) {

        Scanner input = null;
		PrintWriter outputStream  = null;
        String line = null;
        String[] lineParts = null;

		String description;
        double price;
        int count;
        double totalValue = 0.0;
        
        try {
            input = new Scanner(new BufferedReader(new FileReader("c:\\data\\inventory.csv")));
			outputStream = new PrintWriter(new BufferedWriter(new FileWriter("c:\\data\\newinv.csv")));            

            while (input.hasNextLine()) {
                line = input.nextLine();

				// print out the line as-is
                //System.out.println(line);


				// Break the line into an array of strings
                lineParts = line.split(",");
                
				// We know the price is a double, and the count is an integer
				description = lineParts[0];
                price = Double.parseDouble(lineParts[1]);
                count = Integer.parseInt(lineParts[2]);

				// Print them out as separate parts
                System.out.println(description + " " + price + " " + count);

				// Total up the value of all the inventory
                totalValue+= (price * count);

				// Increase the prices by 10%
				price *= 1.1;
			
				// Write the lines back to a file using println()
				outputStream.println(description + "," + price + "," + count);

            }
            
        } catch (IOException ioe ) {
            System.out.println("Could not read file");
            ioe.printStackTrace();
        } finally {
            if (input != null) 
                input.close();
			if (outputStream != null) 
				outputStream.close();
        }
        

        System.out.println("Old Inventory Value: " + totalValue);
        
    }
    
    
}







