Amazon Interview Question for Software Engineer / Developers

Country: United States

Comment hidden because of low score. Click to expand.
of 1 vote

In any object-oriented design question, you first want to start off with asking your
interviewer some questions to clarify design constraints. Is this jukebox playing CD?
Records? MP3s? Is it a simulation on a computer, or is it supposed to represent a
physical jukebox? Does it take money, or is it free? And if it takes money, which
currency? And does it deliver change?

Unfortunately, we don't have an interviewer here that we can have this dialogue with.
Instead, we'll make some assumptions. We'll assume that the jukebox is a computer
simulation that closely mirrors physical jukeboxes, and we'll assume that it's free.
Now that we have that out of the way, we'll outline the basic system components.
• Jukebox
• CD
• Song
• Artist
• Playlist
• Display (displays details on the screen)

Now, let’s break this down further and think about the possible actions.
• Playlist creation (includes add, delete, and shuffle)
• CD selector
• Song selector
• Queuing up a song
• Get next song from playlist

A user also can be introduced:
• Adding
• Deleting
• Credit information

Each of the main system components translates roughly to an object, and each action
translates to a method. Let's walk through one potential design.

The Jukebox class represents the body of the problem. Many of the interactions
between the components of the system, or between the system and the user, are
channeled through here.

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> February 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

public class Jukebox { 
 private CDPlayer cdPlayer; 3 private User user;
 private Set<CD> cdCollection;
 private SongSelector ts; 
 public Jukebox(CDPlayer cdPlayer, User user, 
 Set<CD> cdCollection, SongSelector ts) { 
 public Song getCurrentSong() { 
 return ts.getCurrentSong(); 
 public void setUser (User u) { 
 this. user = u; 

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> February 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
of 0 votes

Like a real CD player, the CDPlayer class supports storing just one CD at a time. The
CDs that are not in play are stored in the jukebox.

class CDPlayer { 
 private Playlist p; 
 private CD c; 
 /* Constructors. */ 
 public CDPlayer(CD c, Playlist p) { ... } 
 public CDPlayer(Playlist p) { this.p = p; } 
 public CDPlayer(CD c) { this.c = c; } 
 /* Play song */ 
 public void playSong(Song s) { ... } 
 /* Getters and setters */ 
 public Playlist getPlaylist() { return p; } 
 public void setPlaylist(Playlist p) { this.p = p; } 
 public CD getCD() { return c; } 
 public void setCD(CD c) { this.c = c; } 

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> February 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
of 0 votes

The Playlist manages the current and next songs to play. It is essentially a wrapper
class for a queue and offers some additional methods for convenience.

public class Playlist { 
 private Song song; 
 private Queue<Song> queue; 
 public Playlist(Song song, Queue<Song> queue) { 
 public Song getNextSToPlayQ { 
 return queue. peek(); 
 public void queueUpSong(Song s) { 
 queue. add(s); 

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> February 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
of 0 votes

The classes for CD, Song, and User are all fairly straightforward. They consist mainly of
member variables and getters and setters.

public class CD { 
 /* data for id, artist, songs, etc */ 
 public class Song { 
 /* data for id, CD (could be null), title, length, etc */ 
 public class User { 
 private String name; 
 public String getName() { return name; } 
 public void setName(String name) { } 
 public long getlD() { return ID; } 
 public void setID(long ID) { ID = iD; } 
 private long ID; 
 public User(String name, long iD) { … } 
 public User getUser() { return this; } 
 public static User addUser(String name, long iD) { ... } 

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> February 26, 2014 | Flag

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More