Design patterns in classes

Design a car rental model

Implement the accessor functions and a CarRental class which contains the container to store them.
A car rental company wants to keep track of its cars. Each vehicle has a license plate and a brand. (eg. BWM). Currently the company has SUV-s and Sedans. SUV-s have an optional third row seat, sedan’s have an optional sport package. Each car can be queried to inquire the number of passengers it can carry.

NKD on May 19, 2010 |Edit | Edit

We can use the Decorator Pattern
Class Car
{
public:
int license;
string brand;
virtual int MAXSeats() = 0;
}
class SUV-s:public Car
{
int seats;
int extra_Seats;
SUV-s()
{
exta_seats = 1;
}
int MAXSeats()
{
return (seats+extra_seats);
}
}

Designing an elevator:

Design an elevator.

3

[Full Interview Report]

Tags: Amazon » Software Engineer / Developer

Question #387979 (Report Dup) | Edit | History

Anonymous on February 23, 2010 |Edit | Edit

very easy. maintain an array. each element corresponds to one floor. whenever a request is placed the corresponding bit should be set. Depending on the first request the direction would be set and the array should be scanned in the direction. For instance, say the lift is in fifth floor. A request is placed for floor 2. So direction is set to correspond to down direction. And then if a request to floor 3 is placed and the bit set accordingly. So floor 3 will be served on the way to floor 2. If now the request to floor 4 is placed its bit is set and after reaching floor 2 no more floor is requested then the lift will set the direction bit to correspond to upward direction. A counter will also be set whenever a request is made counter will be increased and when a request is served the counter value will be decreased and when the counter reaches zero the lift will stay there.

clrs on March 24, 2010 |Edit | Edit

almost right!!
but need two arrays ... and u can only knowwhich floor the request comes from not which floor one has to go to.. slight modifications needed

Reply to Comment

becga on March 11, 2010 |Edit | Edit

en.wikipedia.org/wiki/Elevator_algorithm is one, there can be many actually.
The essential problem remains markovian chain.

Design a furniture management system. You will have have to design class Furniture, WoodChair, SteelChair, WoodTable, SteelTable, etc. Each furniture has material(s) -- wood, steel, cotton. You have to design functions: applyFire(), applyWeight(), etc. Make your system easy to extend in order to include more materials and more subclasses like Futon.

1

[Full Interview Report]

Tags: Amazon » Software Engineer / Developer

Question #387978 (Report Dup) | Edit | History

naveen.dixit on May 19, 2010 |Edit | Edit

Decorator pattern
abstract Class Furniture
{
//functions;
}
class WoodChair :public Furniture
{
//function impl
}
class SteelTable :public Furniture
{
//function impl
}
...
...
abstract class FurnitureDecorator : public Furniture
{
//func
}
class Wood : public FurnitureDecorator
{
Furniture decorating_furniture;
//func imp using the functions of decorating_furniture;
}

Given 5 classess Person, Head, Body, Arm, Leg, how will you relate all the 4 classes in a object oriented way?

4

[Full Interview Report]

Tags: Amazon » Object Oriented Design » Software Engineer / Developer

Question #3089709 (Report Dup) | Edit | History

gevorgk on June 08, 2010 |Edit | Edit

Composition...

anil on June 08, 2010 |Edit | Edit

bosy is composed of Arm, Leg, Head.
Every Person has body.

Anonymous on June 08, 2010 |Edit | Edit

No, body can be just the torso without arms and legs

Anonymous on June 08, 2010 |Edit | Edit

No, body can be just the torso without arms and legs

Add an Interview Question

Amazon Interview Question for Software Engineer / Developers

Anonymous on June 08, 2010

What is the visitor pattern?
Difference between Facade and Adapter Pattern?

1

[Full Interview Report]

Tags: Amazon » Software Engineer / Developer

Question #3094698 (Report Dup) | Edit | History

netappreject on June 08, 2010 |Edit | Edit

Visitor pattern is to make double dispatch i.e. make a virtual method callable based on two objects rather than one as we normally see.

Diff between facade and adapter: Facade is for unified simple inteface combining functionality of several classes. Adapter is used to provide extensible functionality by privately inheriting the adaptee class.