Guest User

Untitled

a guest
Apr 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.util.ArrayList;
  2. /**
  3.  * Class to test CD implementation
  4.  *
  5.  * @author marc/murray
  6.  * @version December 2004/2007
  7.  */
  8. public class CDTester
  9. {
  10.     public void test()
  11.     {
  12.     CD mycd = new CD("Van Morrison", "Astral Weeks", 4);
  13.     // add some tracks
  14.    
  15.     mycd.addTrack(1, new Track("Slim Slow Rider", 423));
  16.     mycd.addTrack(2, new Track("Astral Weeks", 320));
  17.     mycd.addTrack(3, new Track("Young Lovers Do", 276));
  18.     mycd.addTrack(4, new Track("Ballerina", 365));
  19.  
  20.     // find out total
  21.     System.out.println("Total running time is " + mycd.totalRunningTime());
  22.     // Result should be Total running time is 23:04
  23.  
  24.     // find longest track
  25.     System.out.println("Track with longest running time is " + mycd.longestTrack());
  26.     // Result should be Track with longest running time is Slim Slow Rider
  27.    
  28.     CD myothercd = new CD("Teenange Fanclub", "Thirteen", 1);
  29.     myothercd.addTrack(1, new Track("Fear of Flying", 324));
  30.     System.out.println("Total running time is " + myothercd.totalRunningTime());
  31.     // Result should be Total running time is 5:24
  32.    
  33.     // find longest track
  34.     System.out.println("Track with longest running time is " + myothercd.longestTrack());
  35.     // Result should be Track with longest running time is Fear of Flying
  36.  
  37.     // challenge exercise - find tracks
  38.     /* Remove these comments to test these if you have attempted it
  39.         System.out.println("Track with 'er' are :");
  40.         ArrayList <String> tracks = mycd.findTracks("er");
  41.         for (String s : tracks) {
  42.             System.out.println(s);
  43.         }
  44.     */
  45.     /* Result should be:
  46.     Track with 'er' are :
  47.     Slim Slow Rider
  48.     Young Lovers Do
  49.     Ballerina
  50.     */
  51.    }
  52. }
Add Comment
Please, Sign In to add comment