title: File I/O Basics
body: <p>I'm working on a school programming lab and I've gotten stuck.  The book is not too helpful in teaching how to format I/O properly, or at least I'm not understanding it properly.  I need a bit of help getting on with the next steps, but here's the full requirements of the program I'm supposed to be making:</p>
  
  <blockquote>
    <p>A hotel salesperson enters sales in a text file. Each line contains
    the following, separated by semicolons: The name of the client, the
    service sold (such as Dinner, Conference, Lodging, and so on), the
    amount of the sale, and the date of that event. Write a program that
    reads such a file and displays the total amount for each service
    category. Display an error if the file does not exist or the format is
    incorrect. In addition to the program specifications listed, your
    program should both print the results as well assend the results to a
    separate output file.</p>
  </blockquote>
  
  <p>Example of input.txt:</p>
  
  <blockquote>
    <p>Elmer Fudd;Lodging;92.00;11-01-2014</p>
    
    <p>Elmer Fudd;Conference;250.00;11-02-2014</p>
    
    <p>Daffy Duck;Dinner;19.89;11-02-2014 </p>
    
    <p>Daffy Duck;Conference;275.00;11-02-2014 </p>
    
    <p>Mickey Mouse;Dinner;22.50;11-02-2014</p>
    
    <p>Mickey Mouse;Conference;275.00;11-02-2014</p>
  </blockquote>
  
  <p>I'm currently stuck on figuring out how to get the file properly loaded and formatted, which I think I did right, but then my professor suggested breaking each into it's own line, but nowhere in my book does it clearly tell how to do that.  Just to be clear, I'm not looking for a coding miracle, I just would like someone to help guide me in the right direction as to what I should do next.  Possibly a better way to handle this situation in a nicely detailed guide?   Nothing fancy though.  Thank you in advance, and here's my current code.</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  public class Sales
  {
      public static void main(String[] args) throws FileNotFoundException
      {
              File inputFile = new File("input.txt");
              Scanner in = new Scanner(inputFile);
              PrintWriter out = new PrintWriter("output.txt");
              double dinnerTotal = 0;
              double conferenceTotal = 0;
              double lodgingTotal = 0;
              Scanner lineScanner = new Scanner(inputFile);
              lineScanner.useDelimiter(";");
              while (lineScanner.hasNext())
              {
                  String line = in.nextLine(); //Here's where I'm really stuck
                  System.out.print(line); //Not to say I'm not stumped all over.
              }
              in.close();
              out.close();
              lineScanner.close();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>From what Jason said, I'm at this now:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  public class Sales
  {
      public static void main(String[] args) throws FileNotFoundException
      {
          File inputFile = new File("input.txt");
          Scanner in = new Scanner(inputFile);
          PrintWriter out = new PrintWriter("output.txt");
          double dinnerTotal = 0;
          double conferenceTotal = 0;
          double lodgingTotal = 0;
          while (in.hasNext())
          {
              String line = in.nextLine();
              String[] parts = line.split(";");
              if(parts[1].equals("Conference")) {
                  conferenceTotal += Double.parseDouble(parts[2]);
              } else if(parts[1].equals("Dinner")) {
                  dinnerTotal += Double.parseDouble(parts[2]);
              } else if(parts[1].equals("Lodging")) {
                  lodgingTotal += Double.parseDouble(parts[2]);
              }
          }
          in.close();
          out.close();
      }
  }
  </code></pre>