Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

package careercup.test.amazon;

import java.util.Collection;

/**
 * 
	design a library for borrowing books and renewing.
	
	1. On Borrowing
	 	
	 	Verify user validations .
	 	perform borrowing 
	 	
	2. On renewal
	   
	    verify user validations
	    perform renewal .
	   
	
 * @author dileep
 *
 */
public class LibraryForBooksBorrowing {

	/**
	 * 
	 */
	public void onBorrowing(Book book,User user){
		// Do some validations
		user.borrowBook(book);
	}
	
	/**
	 * 
	 * @param b
	 * @param user
	 */
	public void onRenewal(Book b, User user){
		user.renewalBook(b);
	}
	
	/**
	 * 
	 * @author dileep
	 *
	 */
	private static class User{
		private final long userId=0;

		private Collection<Book> borrowedBooks;
		
		public void borrowBook(Book b){
			borrowedBooks.add(b);
		}
		
		public void renewalBook(Book b){
			if(borrowedBooks.contains(b)){
				// perform renewal operation .
			}
		}

		public boolean isRenewalExceeded() {
			// TODO Auto-generated method stub
			return false;
		}
		
	}
	
	/**
	 * 
	 * @author dileep
	 *
	 */
	private static class Book{
		private final long UNIQUE_CODE= 0;
	}
	
	/**
	 * 
	 * 1.Adds new Book backed by a store..
	 * 2. Deletes ...
	 * 
	 * @author dileep
	 *
	 */
	private static class BookStore{
		
		private Collection<Book> books;
	}
	
	/**
	 * performs User level operations .
	 * 1. Adds a new User 
	 * 2. Deleted existing User
	 * 3. performs appropriate actions when lending date is reached ...
	 * 		a) sends e-mail 
	 *     b) calculates total fine .
	 */
	private static class Users{
		
		private Collection<User> allMembers;
	
		/**
		 * iterate over all users , do checks on renewal..
		 */
		public void doThisEveryDay(){
		
			for(User user:allMembers){
				
				if(user.isRenewalExceeded()){
					//Send e-mail 
					// Calculate fine 
				}
			}
		}
		
	}
}

- dileep July 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

If you can explain the class level design of the above code.

- spiderman July 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A typical library has a set of books which the users can borrow for a certain period of time and return back. Users may choose to renew the return date if they feel they need to more time to read the book. We are trying here to design an online library.

The typical user actions with this online library would be

sign in/register
search books
borrow books
renew the return date for any of the books borrowed
view his profile(check his details, list of books he borrowed )

The online library should support all the above actions. It must keep track of the different books in the library currently available for users to borrow and also the books already borrowed bu users. Put it simply the inventory should be managed.

Going through the above description we can think of these components in the system:

User
Book
BorrowTxn -> record for the event for book b is borrowed by user u
InventoryManager -> manages the books in the library. Adds new books, remove books and respond to book search requests
LibraryManager-> Allows user interaction with the library like logging in, borrowing, renewal and return.

I have out the class diagram at
h%t%t%p://thought-works.blogspot.in/2012/11/object-oriented-design-for-library-to.html
(remove % in the url and paste)

- sriniatiisc November 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

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

Books

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

Videos

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