Amazon Interview Question for SDE-2s


Country: India
Interview Type: Phone Interview




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

class DVD
 {
    int id;
    double price;
    string  Name;
    int  status;  // Availabe(or) Rented
    string customer; // custid
    string  StartDate; // Rent Start Date
    string  Enddate;  // Rent End Date
   
  public:
    // get,set methods
}


class DVDLibrary
{
   // map of dvd id and pointer to DVD object
   map<int,DVD *>   collection1;

   // multimap of name of DVD to dvd id
   multimap<string,	int>   collection2;

  public:
   //methods to modify collection1 and collection2
}

class Customer
{
   string customer;

   list<DVD *>   dvdlist;
   
   list<Payment *> paymentlist;

 public:
  //methods
}

class Payment
{
   string customer;

   float  amt;
 
   string paymentdate;

  public:
  // methods
}

- Anonymous July 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

hmm.. looks good. Can you please also enlist the functions/methods and collaborations among these classes.
by

Customer::paymentlist;

did you mean the transaction history?

Few suggestions:
1)

DVDLibrary

should also have customer list.
2)

class Customer

can have privileges. By it I mean privileges like: restricted access, power_user etc. where

privilege

can be either property or class in its own right depending upon the complexity of

privilege

3)There's also need for:

class Transactions
{
	Customer& cust;
    list<Dvd*> borrowed;
	Date& transaction date;
public:
//methods
};

4)

class Payment

can have field: discount offered.

More enhancements can be followed.. your take?

- pavi.8081 July 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think DVD class should not contain start and end date. That needs to be maintained separately by your controller (DVD Library).

How would you find who has taken a particular DVD? This also needs to be maintained by DVD Library

- gmahindra0 October 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think DVD class should not contain start and end date. That needs to be maintained separately by your controller (DVD Library).

How would you find who has taken a particular DVD? This also needs to be maintained by DVD Library

- Gourav October 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is the design for library where books are rented. Replace books with dvds and the design should work. thought-works.blogspot.in/2012/11/object-oriented-design-for-library-to.html

- sriniatiisc December 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream> 
#include <map>
#include<string>
using namespace std; 


class DVD
{
    string sName_;
    int iD_;
    string sDescrption_;
    int iRent_;
    bool bRented_;
    public:
        DVD(string name, int id, int rent, string desc = "") : sName_(name), iD_(id), 
            sDescrption_(desc), iRent_(rent), bRented_(false){}
        const char* GetName() const
        {
            return sName_.c_str();
        }
        const char* GetDescription() const
        {
            return sDescrption_.c_str();        
        }
        int GetID() const
        {
            return iD_;
        }
        int GetRent() const
        {
            return iRent_;
        }
        bool IsRented() const
        {
            return bRented_;
        }
        bool SetRentStatis(bool bRented)
        {
            bRented_ = bRented;
        }
};

class Customer
{
    string sAddress_;
    string sCustName_;
    bool bIsMember_;    
    int iCustId_;
    public:
        Customer(int id, string name, string address,bool member=false) : sCustName_(name),
                sAddress_(address), bIsMember_(member), iCustId_(id)
                {}
        const char* GetName() const
        {
            return sCustName_.c_str();
        }
        const char* GetAddress() const
        {
            return sAddress_.c_str();
        }
        bool IsMember() const
        {
            return bIsMember_;
        }
        bool SetMember() 
        {
            bIsMember_ = true;
        }
};

class DVDLibrary
{
    private:
        //! Table of id vs DVD
        map<int, DVD*> mIDTableDVD_;
        //! name of DVD vs DVD pointers.
        multimap<string, DVD*> mmTableOfNameDVD_;
        //! Multimap of customer id vs DVD's with that customer.
        multimap<int, DVD*> mmTableOfCustNameDVD_;
        //! ID vs customer table.
        multimap<int, Customer*> mIDCustomerTable_;
    public:
        DVDLibrary(){}

        //! Add DVD to the store.  
        //! Create a DVD pointer and 
        //! Update mIDTableDVD_, mmTableOfNameDVD_
        bool AddDvd(); //! Add dvd details as params
        //! Remove DVD from the store.
        //! Clear entry from mIDTableDVD_,mmTableOfNameDVD_
        bool RemoveDvd();
        //! Ask the Customer Id.
        //! Check if the max number of the DVD's reached, If not give DVD 
        //! and do not prepare report.
        //! set DVD status to rented. 
        bool RentDvdToMember();
        //! Customer has agreed to buy the DVD.
        //! Get Customer details. Create new customer. Add it to mIDCustomerTable_
        //! Get Payment for each DVD
        //! set DVD status to rented.
        bool RentDvdToCustomer();
        //! Let customer return DVD.
        //! Update mmTableOfCustNameDVD_ and set the DVD status to not Rented.
        bool RetrunDvdByCustomerOrMember(int dvdId, int custID);
        //! Prepare the payment receipt for Customer.
        //! To be called by RentDvdToCustomer.
        string PrepareReceipt(int dvdId, Customer* cust);

};

- Pankaj Kumar January 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is exactly how I approached it. I think having two more classes, one called Transactions, and one called CreditCard may help the design. A transaction contains a Customer and a CreditCard and has its own unique_id. In your data library class you can maintain a set of these Transaction objects.

- Abhay Curam February 04, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It doesn't look it supports renewing a DVD, checkin or checkout

- Guy February 11, 2014 | Flag


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