mardi 28 avril 2015

Java - else in the loop statement keeps executing

this has me stumped. Im using a loop to go through an array and then using ifs/else to find whether it meets the criteria. However the else statement keeps being executed even though an if is being executed aswell. Probably something really basic im missing. I need to check in the if statements twice as the user is entering a genre aswell as the item in the array meets that genre too.

cheers

  for (int i = 0; i < movies.length; i++)
  {
     //RentalMovie movie = movies[i];

     if(movies[i].getMovieGenre().equalsIgnoreCase("action") && movies[i].getMovieGenre().equalsIgnoreCase(genreID))
     {
        genreList += movies[i].getMovieID() + " - " + movies[i].getMovieTitle() + "[" + movies[i].getMediaType() + "]\n";
     }
     else if(movies[i].getMovieGenre().equalsIgnoreCase("childrens") && movies[i].getMovieGenre().equalsIgnoreCase(genreID))
     {
        genreList += movies[i].getMovieID() + " - " + movies[i].getMovieTitle() + "[" + movies[i].getMediaType() + "]\n";         
     }
     else if (movies[i].getMovieGenre().equalsIgnoreCase("drama") && movies[i].getMovieGenre().equalsIgnoreCase(genreID))
     {
        genreList += movies[i].getMovieID() + " - " + movies[i].getMovieTitle() + "[" + movies[i].getMediaType() + "]\n";            
     }
     else
     {
        genreList += "- No rental movies were found for the genre: " + genreID; 
     } 

  }

Aucun commentaire:

Enregistrer un commentaire