Amazon Interview Question for SDE-2s


Country: United States
Interview Type: In-Person




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

I will use different design patterns for the design of this application.

Design Patterns involved:


1) Builder Design Pattern (For adding food item and ordering)

2) Interpreter Design Pattern (User can Search Different restaurant)

3) Iterator Pattern (User Sees Menu)

4) Observer Pattern(Track an order in Real Time)

5) Command Pattern(Order or Cancellation of Food)

Please refer to below Code Repository for more details:


https://github.com/gmershad/FoodDeliveryApp

- mailtogulershad December 25, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

We can consider few more conditions-

Restaurant has a Menu (Menu class)
Menu has items (Item class)
User can order (Order class)
Order can have many selectedItems(SelectItem class)
User has to pay the BIll (Bill class)
There also be a Payment class(That must be thread safe)


Total - 8 classes

Restaurant
User
Menu
Item
Order
SelectItem
Bill
Payment


Lets see classes one by one -

Restuarant
-----------
- name : String
- location : string
- conatct : string
-----------
+ isOpen() : boolean
+ getName() : String
+ getLoaction() : String
+ getContact() : String
+ setContact()
+ displayMenu()
+ updateMenu)_
+ generateBill()


User
-----------
- uid : String
- contact : String
-----------
+ setContact()
+ getContact()
+ getUid()
+ searchRestauranr()
+ selectRestuarant()
+ newOrder()
+ cancelOrder()
+ trackOrder()
+ payBill()


Menu
---------
- menu : List<Item>
---------
+ displayMenu()
+ updateMenu()
+ addItem()
+ deleteItem()


Item
----------
- itemId : String
- price : float
- name : String
----------
+ setItemId(String)
+ setName(String)
+ setPrice(float)
+ getItemId()
+ getName()
+ getPrice()


Order
-----------
- orderId : String
-----------
+ getStatus() // To track the order
+ updateStatus() // Restaurant admin can update it
+ getOrderId()
+ selectItem()
+ removeItem()
+ updateItem()


SelectItem
-----------
- itemId
- quantity : int
-----------
+ getItem()
+ setItem()
+ getQuantity()
+ setQuantity()


Bill
------------
- billNum
- orderId
------------
+ getBillNum()
+ getTotalAmount()
+ displayBill()


Payment
------------
- pid : String
- pType : String
- billNum : String
-------------
+ successfulyPaid() : boolean

- azambhrgn December 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can divide each use case into micro-services. lets Say:
/search?query //give search result in json format
/restaurant_name //gives detail for particular restaurant in json format
| //reqeust followed by restaurant_name/changemenu
--> PUT for /restaurant_name/changemenu
--> DELETE for /resaurant_name/deletemenu
order/user
|
-->POST for order/user/addItem
-->POST for order/user/addItems
-->DELETE for order/user/deleteItem
-->DELETE for order/user/deleteItems
-->POST or DELETE for order/user/cancelorder
-->GET for order/user/tracklocation
/pay -->POST for /pay redirect to payment gateway

Here i assumed broadly five tables User(u_name, address), Restaurant(r_name, menu),
Order(o_id, u_name, items, total, status), Location(o_id, location_detail)

UI will use these REST endpoint to perform a specific task. For example /search?query to search a restaurant. At server side this /search endpoint calls the database table Restaurant to search for particular restaurant and return all restaurant matching query criteria in json format.

Similarly for other use cases also this REST based micro-service architecture will be use.

- Rahul Raghuvanshi December 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can divide each use case into micro-services. lets Say:
/search?query //give search result in json format
/restaurant_name //gives detail for particular restaurant in json format
| //reqeust followed by restaurant_name/changemenu
--> PUT for /restaurant_name/changemenu
--> DELETE for /resaurant_name/deletemenu
order/user
|
-->POST for order/user/addItem
-->POST for order/user/addItems
-->DELETE for order/user/deleteItem
-->DELETE for order/user/deleteItems
-->POST or DELETE for order/user/cancelorder
-->GET for order/user/tracklocation
/pay -->POST for /pay redirect to payment gateway

Here i assumed broadly five tables User(u_name, address), Restaurant(r_name, menu),
Order(o_id, u_name, items, total, status), Location(o_id, location_detail)

UI will use these REST endpoint to perform a specific task. For example /search?query to search a restaurant. At server side this /search endpoint calls the database table Restaurant to search for particular restaurant and return all restaurant matching query criteria in json format.

Similarly for other use cases also this REST based micro-service architecture will be use.

- Rahul Raghuvanshi December 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can divide each use case into micro-services. lets Say:
/search?query //give search result in json format
/restaurant_name //gives detail for particular restaurant in json format
| //reqeust followed by restaurant_name/changemenu
--> PUT for /restaurant_name/changemenu
--> DELETE for /resaurant_name/deletemenu
order/user
|
-->POST for order/user/addItem
-->POST for order/user/addItems
-->DELETE for order/user/deleteItem
-->DELETE for order/user/deleteItems
-->POST or DELETE for order/user/cancelorder
-->GET for order/user/tracklocation
/pay -->POST for /pay redirect to payment gateway

Here i assumed broadly five tables User(u_name, address), Restaurant(r_name, menu),
Order(o_id, u_name, items, total, status), Location(o_id, location_detail)

UI will use these REST endpoint to perform a specific task. For example /search?query to search a restaurant. At server side this /search endpoint calls the database table Restaurant to search for particular restaurant and return all restaurant matching query criteria in json format.

Similarly for other use cases also this REST based micro-service architecture will be use.

- rahul.raghuvanshi.42 December 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I will prefer these patterns for this app
1) Iterator pattern - for displaying menu suggested in one comment
2) Singleton - For DB access
3) Decorator for menu selection from user
4) Observer for menu change from the Restaurant owner

- Anonymous December 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My design would be :-

-> Restaurant will be the abstract class which will contain the Map<restaurantName,Restaurant> ( where restaurantName is the name of the restaurant in string format and Restaurant is the instance of the restaurant added.)

public abstract class Restaurant {

protected String restaurantName;
protected String restaurantLocation;
protected Map<Integer, String> restaurantMenu;
public abstract boolean changeMenu();
public abstract FoodItems addItemsFromMenu();
public abstract void trackTheOrder();

/**
* Order cannot be cancelled after the the order has departed
*
* @return
*/
public abstract boolean cancelOrder();



boolean registerRestaurant(String nameOfRestaurant, Restaurant restaurant) {
restaurantMap.put(nameOfRestaurant, restaurant);
return true;

}



}


class Chutneys extends Restaurant {

Chutneys()
{
registerRestaurant("Chutneys",this);
}
...
}

class OliveGarden extends Restaurant{
...
}

- Amansh January 08, 2017 | 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