27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Solutions</strong> to Chapter 7 | Object Oriented Design<br />

16 private CDPlayer cdPlayer;<br />

17 private User user;<br />

18 private Set cdCollection;<br />

19 private TrackSelector ts;<br />

20<br />

21 public JukeBox(CDPlayer cdPlayer, User user, Set cdCollection,<br />

22 TrackSelector ts) { ... }<br />

23 public Song getCurrentTrack() { return ts.getCurrentSong(); }<br />

24 public void processOneUser(User u) { this.user = u; }<br />

25 }<br />

26<br />

27 public class Playlist {<br />

28 private Song track;<br />

29 private Queue queue;<br />

30 public Playlist(Song track, Queue queue) { ... }<br />

31 public Song getNextTrackToPlay(){ return queue.peek(); }<br />

32 public void queueUpTrack(Song s){ queue.add(s); }<br />

33 }<br />

34<br />

35 public class Song {<br />

36 private String songName;<br />

37 }<br />

38<br />

39 public class TrackSelector {<br />

40 private Song currentSong;<br />

41 public TrackSelector(Song s) { currentSong=s; }<br />

42 public void setTrack(Song s) { currentSong = s; }<br />

43 public Song getCurrentSong() { return currentSong; }<br />

44 }<br />

45<br />

46 public class User {<br />

47 private String name;<br />

48 public String getName() { return name; }<br />

49 public void setName(String name) { this.name = name; }<br />

50 public long getID() { return ID; }<br />

51 public void setID(long iD) { ID = iD; }<br />

52 private long ID;<br />

53 public User(String name, long iD) { ... }<br />

54 public User getUser() { return this; }<br />

55 public static User addUser(String name, long iD) { ... }<br />

56 }<br />

1 5 5<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Concepts <strong>and</strong> Algorithms

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!