Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1.  
  2. /**
  3. * In the Question 2 class, write a method 'longestTrack' that takes
  4. * an ArrayList of Tracks in an album (defined in the Track class),
  5. * as input and returns the track in the album with the
  6. * longest duration.
  7. * If the list of tracks is empty, the method should return null.
  8. *
  9. * Eg:
  10. *
  11. * ArrayList<Track> starWars = new ArrayList<Track>();
  12. *
  13. * Track track1 = new Track("Main Title", 134);
  14. * Track track2 = new Track("Imperial Attack", 403);
  15. * Track track3 = new Track("The Dune Sea", 302);
  16. *
  17. * starWars.add(track1);
  18. * starWars.add(track2);
  19. * starWars.add(track3);
  20. *
  21. * Track longest = Question2.longestTrack(starWars);
  22. * System.out.println(longest.getTitle());
  23. *
  24. * This should print "Imperial Attack".
  25. *
  26. */
  27.  
  28. import java.util.ArrayList;
  29.  
  30. public class Question2
  31. //what tracks? Add tracks - we arent doing has to be seperate method
  32. //once tracks are added we loop through them
  33. //and filter by duration
  34. //the duration filter must compare the one previous to the one after
  35. {
  36.  
  37. private ArrayList<Track>longestTrack;
  38. private String name;
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. public Track longest(ArrayList<Track>longestTrack) {
  46.  
  47. this.longestTrack = new ArrayList<Track>();
  48.  
  49. for (Track i : longestTrack){
  50. this.longestTrack.add(i);
  51.  
  52. if (i.getDuration() > i.getDuration()){
  53.  
  54. longestTrack.getTitle();
  55. }
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement