title: Very Basic Java: For-Loop in Java method won't run
body: <p>I've never asked a question on this before but I'd appreciate any help anyone can provide. I'm currently learning the fundamentals of Java so this is more than likely a very basic problem. When I call this method, nothing seems to happen and I can't figure out why. I could just change it to type void and use system.print but I'd rather not, anyhow here's the code:</p>
  
  <pre><code>public double calcTotal()
  {
      double total = 0.00;
  
      for (int i = 0; i &lt; jSongs.size(); i++)
      {
          total += jSongs.get(i).getPrice();
      }
  
      return total;
  }
  </code></pre>
  
  <p>I think it would be easier if I just showed you guys the whole lot, this is the app that's calling the methods to test them:</p>
  
  <pre><code>public class JukeboxApp {
      public static void main(String[] args) {
          Song s1 = new Song("Metallica", "The Unforgiven", 1.25, 6.23);
          Song s2 = new Song("Test Artist 2", "Test Title 2", 4.00, 3.40);
          Song s3 = new Song("Test Artist 3", "Test Title 3", 6.00, 2.50);
          Jukebox jb = new Jukebox();
          jb.addSong(s1);
          jb.addSong(s2);
          jb.addSong(s3);
          jb.displaySongs();
          jb.removeSong("The Unforgiven");
          jb.searchSong("Test Title 2");
          jb.calcTotal();
      }
  
  }
  </code></pre>
  
  <p>Here is the jukebox class, which I'm sure is full of mistakes:</p>
  
  <pre><code>import java.util.ArrayList;
  public class Jukebox {
  private String name;
  private ArrayList&lt;Song&gt; jSongs;
  
  public Jukebox()
  {
      name = "Primary Jukebox";
      jSongs = new ArrayList&lt;Song&gt;();
  }
  
  public String getName()
  {
      return name;
  }
  
  public double calcTotal()
  {
      double total = 0.00;
  
      for (int i = 0; i &lt; jSongs.size(); i++)
      {
          total += jSongs.get(i).getPrice();
      }
  
      return total;
  }
  
  public void searchSong(String sTitle)
  {
      boolean check = false;
      if ( jSongs.size() == 0 ) {
          System.out.println("The are no songs in the list.");
          check = true;
      } else if ( jSongs.size() != 0 ) {
          for ( int i = 0; i &lt; jSongs.size(); i++ ) {
              if ( jSongs.get(i).getTitle().equals(sTitle) == true ) {
                  check = true;
                  System.out.println(jSongs.get(i));
              }
          }
      }
      if ( check == false ) {
          System.out.println("The searched song could not be found.");
      }
  }
  
  public String searchArtist(String sArtist)
  {
      int countMatch = 0;
      for (int i = 0; i &lt; jSongs.size(); i++) {
          if ( jSongs.get(i).getArtist().equals(sArtist) ) {
              countMatch++;
              return jSongs.get(i).getTitle();
          } else if ( countMatch == 0 ) {
              return "The requested artist could not be found.";
          }
      }
      return "If you would like to search for another artist, please enter the corresponding number.";
  }
  
  public void addSong(Song s1)
  {
      boolean check = false;
  
      if ( jSongs.size() == 0 ) {
          System.out.println("Your song will be added to the list.");
          jSongs.add(s1);
          return;
      } else if ( jSongs.size() != 0 ) {
          for ( int i = 0; i &lt; jSongs.size(); i++ ) {
              if ( jSongs.get(i) == s1 ) {
                  check = true;
              }
          }
      }
      if ( check == false ) {
          System.out.println("Your song will be added to the list.");
          jSongs.add(s1);
      } else if ( check == true ) {
          System.out.println("Your song is already in the list.");
      }
  }
  
  public void removeSong(String title)
  {
      boolean check = false;
      for ( int i = 0; i &lt; jSongs.size(); i++ ) {
          if ( jSongs.get(i).getTitle().equals(title) ) {
              jSongs.remove(i);
              check = true;
          }
      }
      System.out.println(check);
  }
  
  public void displaySongs()
  {
      for ( int i = 0; i &lt; jSongs.size(); i++ ) {
          System.out.println(jSongs.get(i));
      }
  }
  
  public Song showMostExpensive()
  {
      double price = 0.00;
      Song mostESong = new Song();
      for ( int i = 0; i &lt; jSongs.size(); i++ ) {
          if ( jSongs.get(i).getPrice() &gt; price ) {
              price = jSongs.get(i).getPrice();
              mostESong = jSongs.get(i);
          }
      }
      return mostESong;
  }
  
  public Song showShortest()
  {
      double length = 500.00;
      Song shortest = new Song();
      for ( int i = 0; i &lt; jSongs.size(); i++ ) {
          if ( jSongs.get(i).getLength() &lt; length ) {
              length = jSongs.get(i).getLength();
              shortest = jSongs.get(i);
          }
      }
      return shortest;
  }
  
  public Song mostPlayed()
  {
      int count = 0;
      Song mostPSong = new Song();
      for ( int i = 0; i &lt; jSongs.size(); i++ ) {
          if ( jSongs.get(i).getCount() &gt; count ) {
              count = jSongs.get(i).getCount();
              mostPSong = jSongs.get(i);
          }
      }
      return mostPSong;
  }
  }
  </code></pre>
  
  <p>And here is the class that creates the song objects:</p>
  
  <pre><code>public class Song {
  private String artist;
  private String title;
  private double price;
  private int playCount;
  private double length;
  
  public Song()
  {
      artist = "unknown";
      title = "unknown";
      price = 0.00;
      length = 0.00;
      playCount = 0;
  }
  
  public Song(String artist, String title, double price, double length)
  {
      this.artist = artist;
      this.title = title;
      this.price = price;
      this.length = length;
      playCount = 0;
  }
  
  public String getArtist()
  {
      return artist;
  }
  
  public String getTitle()
  {
      return title;
  }
  
  public double getPrice()
  {
      return price;
  }
  
  public int getCount()
  {
      return playCount;
  }
  
  public double getLength()
  {
      return length;
  }
  
  public void changePrice(double newPrice)
  {
      price = newPrice;
  }
  
  public void playSong()
  {
      playCount++;
      System.out.println(title + " is now playing." + "\n" + toString());
  }
  
  public String toString()
  {
      return artist + "\n"
      + title + "\n"
      + price + "\n"
      + length;
  }
  }
  </code></pre>