title: Simple java method using text.io
body: <p>If somebody could please help me troubleshoot this simple assignment I would be forever thankful! I am very new to Java and cannot understand how to go about debugging this simple code.</p>
  
  <p>I need to:</p>
  
  <p>• Read an external file that has an ice-cream flavor listed on each line</p>
  
  <p>• Count the total number of ice creams</p>
  
  <p>• Count the number of ice creams with the name “strawberry”</p>
  
  <p>• Calculate the percentage of ice creams that are “strawberry”</p>
  
  <p>This is what I have got so far...</p>
  
  <pre><code>package icecreamcounter;
  
  import java.io.*; //Import TextIO
  
  public class IcecreamCounter {
  
  public static void main(String[] args) {
      // Open file for reading; if it cannot be opened, end the program
           try {
       TextIO.readFile("icecream.dat");
    }
    catch (IllegalArgumentException e) {
       System.out.println("Can't open file \"icecream.dat\" for reading!");
       System.out.println("Please make sure the file is present before");
       System.out.println("running the program.");
       System.exit(1);  // Terminates the program.
  
       //read the file
       string flavor;
       int strawb; //Total number of strawberry icecreams
       int totalIcecream; // Total number of icecreams
       double percentageStrawb; //Percentage of icecreams which are strawberry
  
       strawb = 0;
       percentageStrawb = (totalIcecream - strawb)/totalIcecream;
  
       while (!TextIO.eof()) {  // process one line of data.
           flavor = TextIO.getlnString();  // Get the rest of the line.
           totalIcecream = totalIcecream + 1; // Add one to the count of total icecreams
           return totalIcecream;
           if (flavor.equals("Strawberry") { // If icecream name is strawberry 
               strawb=strawb+1;         //then add one to the count of strawberry
               return strawb;
           }
       }
  
       System.out.println("Total number of cones is" totalIcecream);
       System.out.println("Total number of strawberry cones is" strawb);
       System.out.println("Percentage of strawberry cones is" percentageStrawb);
    }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The issue might be with the read file part, but it is also giving me errors at the bottom when I try to print the answers. Also, do I have to return the values for example 'totalIcecream' in order to print it out later? Any help would be much appreciated!</p>