int unratedPlayListRatio = trackDatabase.getUnratedPlayListRatio();    int unratedPlayListCount = (int)Math.round(((double)playListLength) * (((double)unratedPlayListRatio) / 100.0));
int unratedPlayListCount = trackDatabase.getNoOfUnratedOnPlaylist();
  public synchronized Track chooseTrack() {    int playListLength = trackDatabase.getPlayListLength();    int unratedPlayListRatio = trackDatabase.getUnratedPlayListRatio();          //Added by EBD - 11.09.2003      //Maybe use ceiling instead of round?    int unratedPlayListCount = (int)Math.round(((double)playListLength) * (((double)unratedPlayListRatio) / 100.0));          // Remove the track we've just played if necessary.    if (playListIndex < playList.size()) {      Track track = (Track) playList.get(playListIndex);      if (!track.isOnPlayList()) {        notifyRemovedFromPlayList((Track)playList.get(playListIndex));        playList.remove(playListIndex);          // Subtract one from the index because it'll get incremented later.        playListIndex--;      }    }      // Remove extra unwanted items.    while (playList.size() > playListLength) {      int toRemove = playList.size() - 1;      notifyRemovedFromPlayList((Track)playList.get(toRemove));      playList.remove(toRemove);    }      // Maintain a 'toOmit' hash table, which is used to make the choosing      // of tracks not choose ones we have already got on the list.    Set toOmit = new HashSet();    int noOfUnrated = 0;    for (int i = 0; i < playList.size(); i++) {      Track track = (Track) playList.get(i);//      if (!track.isOnPlayList()) {//        if (track.getRating() == 0) {//          notifyRemovedFromPlayList((Track)playList.get(i));//          playList.remove(i);//          if (i < playListIndex)//            --playListIndex;//        }//      }//      else {        toOmit.add(track);        if (!track.isRated())          noOfUnrated++;//      }    }      // Loop around one time for each track which needs to be added to the      // play list. Don't worry too much if we don't exactly that number of      // tracks because it will likely get one next time around.    for (int i = playListLength - playList.size(); i > 0; i--) {      synchronized (trackDatabase) {        Track track = null;/** * Modified by Eric Dalquist - 11.09.2003 * * Now multiple unrated tracks can be selected. */        if (noOfUnrated <= unratedPlayListCount && playList.size() != 0)          track = trackDatabase.chooseUnratedTrack(Utils.getRandom(), toOmit);                  if (track == null)          track = trackDatabase.chooseTrack(Utils.getRandom(), toOmit);          // We couldn't find a track so give up looking.        if (track == null)          break;                  if (!track.isRated())          noOfUnrated++;        toOmit.add(track);        // We want "0% unrated on playlist" to be an absolute.        if (unratedPlayListRatio != 0 || track.isRated()) {          int insertIndex = Utils.getRandom().nextInt(playList.size() + 1);          playList.add(insertIndex, track);          notifyAddedToPlayList(track);          if (insertIndex <= playListIndex)            ++playListIndex;        }      }    }    int size = playList.size();    if (size < 1)      return null;    if (playListIndex >= size)      playListIndex = 0;    //    // Make sure the track you select isn't the same as the track    // that was previously played    //    Track selectedTrack;    if (size == 1) {      selectedTrack = (Track) playList.get(0);    } else {      int currentIndex = playListIndex;      do {        if (++playListIndex >= size)          playListIndex = 0;        selectedTrack = (Track) playList.get(playListIndex);        if (selectedTrack != lastPlayedTrack)          break;      } while (playListIndex != currentIndex);    }    lastPlayedTrack = selectedTrack;    System.out.println("---Play list---");    for (int i = 0; i < playList.size(); i++) {      Track track = (Track) playList.get(i);      if (i == playListIndex)        System.out.print("* ");      else        System.out.print("| ");      System.out.println(track.toString());    }    return selectedTrack;  }