Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * In the Question 2 class, write a method 'longestTrack' that takes
- * an ArrayList of Tracks in an album (defined in the Track class),
- * as input and returns the track in the album with the
- * longest duration.
- * If the list of tracks is empty, the method should return null.
- *
- * Eg:
- *
- * ArrayList<Track> starWars = new ArrayList<Track>();
- *
- * Track track1 = new Track("Main Title", 134);
- * Track track2 = new Track("Imperial Attack", 403);
- * Track track3 = new Track("The Dune Sea", 302);
- *
- * starWars.add(track1);
- * starWars.add(track2);
- * starWars.add(track3);
- *
- * Track longest = Question2.longestTrack(starWars);
- * System.out.println(longest.getTitle());
- *
- * This should print "Imperial Attack".
- *
- */
- import java.util.ArrayList;
- public class Question2
- //what tracks? Add tracks - we arent doing has to be seperate method
- //once tracks are added we loop through them
- //and filter by duration
- //the duration filter must compare the one previous to the one after
- {
- private ArrayList<Track>longestTrack;
- private String name;
- public Track longest(ArrayList<Track>longestTrack) {
- this.longestTrack = new ArrayList<Track>();
- for (Track i : longestTrack){
- this.longestTrack.add(i);
- if (i.getDuration() > i.getDuration()){
- longestTrack.getTitle();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement