How do I put (File soundFile) as the parameters in new Track()?

If Track has a constructor that accepts a File as a parameter, then just create a File and pass it, ie

File f = .... create the file as needed
track = new Track(f);

If Track does not have a constructor that accepts a File as a parameter, then you will have to create that constructor first...

public Track(File aFile) {
   ... do whatever the constructor needs to do
}

or look whether or not track has a set-method that accepts a File-parameter.

public class Player
{
    private PlayList playList;
    private Track    track;



    /**
     * Constructor ...
     */
    public Player()
    {
        playList = new PlayList("audio");
    }

       /**
     * Return the track collection currently loaded in this player.
     */
    public PlayList getPlayList()
    {
        return playList;
    }

    /**
     * 
     */
    public void play()
    {
        if(track != null) {
           track.play();
        }    
    }

    public void stop()
    {
        if(track != null) {
           track.stop();  
        }
    }

    /**
     * 
     */
    public void setTrack(int trackNumber)
    {

    }

    /**
     * 
     */
    public String getTrackName()
    {
        return track.getName();
    }

    /**
     * Return information about the currently selected track. The information
     * contains the track name and playing time, in the format
     *    track-name (playing time)
     * Return an empty string if no track is selected.
     */
    public String getTrackInfo()
    {
        if(track != null) {
           System.out.println(track.getName() + "(" + track.getDuration() + ")");
        }
        return " ";
    }
}    

Do I create a int field to assign in the setTrack method? My code compiles but I can not play any songs in the GUI class. Can someone go over my work? Thank you.

in a setTrack method, I would expect an instance of Track being passed as parameter, something like this:

public void setTrack(Track newTrack){
this.track = newTrack;
}

but the parameter is an int . I can't change the method details. shouldn't I use a local variable?

Ok I completed the setTrack method.

 public void setTrack(int trackNumber)
    { 
        Track pTrack;
        if(track != null) {
            pTrack = track;
            pTrack.stop();
        }
        track = playList.getTrack(trackNumber); 
        track.rewind();
    }
 I need help in this method, can someone help?

> /**
>      * Return information about the currently selected track. The information
>      * contains the track name and playing time, in the format
>      *    track-name (playing time)
>      * Return an empty string if no track is selected.
>      */
>     public String getTrackInfo()
      {

      }
 return track.getName()+ "(" + track.getDuration() + ")";

I know that'll return the name and playing time but if no track is selected I need to have an empty string. So how do I write this?

ok I solved that as well ..

I need help with ...

Challenge tasks
Implement three more methods:
• one method named getNumberOfTracksPlayed that returns the number of tracks that
have been played (i.e. that have been started) since the player was started. The return
value should be an int.
• one method named getTotalPlayedTrackLength that returns the total playing time of all
tracks that have been played (or, to be more precise: started to play. We don’t care
whether they were played completely). The result is an int.
• one method named averageTrackLength that returns the average length of the tracks
played. The result is of type double.

public int getNumberOfTracksPlayed()
{
}

public int getTotalPlayedTrackLength()
{
}

public double averageTrackLength()
{
}

keep static counters for these variables, that you augment each time you play a new track.
please ask new questions in a new thread, otherwise it'll become very difficult to follow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.