Amazon Interview Question for Java Developers


Country: United States
Interview Type: Phone Interview




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

sorry. Did not realized it should be for Java. Also movieDiscount should be summed

- LBaralgeen June 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Chain of Responsibility pattern

- Anonymous June 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what kind of responsibility flow do you see here ?

- anonymous June 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

k-mingle.blogspot.in/2014/12/chain-of-responsibility-design-pattern.html

- abc December 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

class TMovie
{
public:
    enum eType { e2D = 0, e3D = 30, e4D = 50 };
    eType m_type;

    TMovie( eType type )
    {
        m_type = type;
    }
};

class TTicket
{
public:
    enum eAge { adult = 0, kid = 50, senior = 30 };

    eAge     m_ageDiscount;

    TTicket( eAge age )
    {
        m_ageDiscount = age;
    };
};

class TPurchase
{
public:
    static float           m_SinglePrice;
    TMovie  *              m_movie;
    std::vector<TTicket *> m_basket;
    int                    m_dayOfWeek;  

    int GetCurrentDayOfWeek()
    {
        return 3;
    }

    void Add( TTicket::eAge age, size_t num )
    {
        for( size_t i = 0; i < num; i++ )
        {
            m_basket.push_back( new TTicket( age ) );
        }
    }

    TPurchase( TMovie::eType type )
    {
        m_dayOfWeek = GetCurrentDayOfWeek();
        m_movie = new TMovie( type );
    };

    ~TPurchase()
    {
        for( size_t i = 0; i < m_basket.size(); i++ )
        {
            delete m_basket[i];
        }
    }

    float GetTotalPrice()
    {
        float price = 0.0;

        for( size_t i = 0; i < m_basket.size(); i++ )
        {
            float ageDiscount = m_basket[i]->m_ageDiscount *  m_SinglePrice / 100;
            float dayDiscount = ( 2 == GetCurrentDayOfWeek() ? 50 : 0 )  *  m_SinglePrice / 100;
            float movieDiscount = m_movie->m_type * m_SinglePrice / 100;

            price += m_SinglePrice - ( dayDiscount > 0 ? dayDiscount : ageDiscount ) - movieDiscount;
        }
        return price;
    }
};

float TPurchase::m_SinglePrice = 10.0;

void testAmazon13878774()
{
    TPurchase  tickets( TMovie::e2D ); 

    tickets.Add( TTicket::eAge::adult, 2 );
    tickets.Add( TTicket::eAge::kid, 3 );
    tickets.Add( TTicket::eAge::senior, 1 );

   cout << " Totoal price: " << tickets.GetTotalPrice() << endl;
}

- LBaralgeen June 11, 2012 | Flag Reply


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