Skip to content

Commit

Permalink
FoodKart flipkart machine coding
Browse files Browse the repository at this point in the history
  • Loading branch information
gowtkum committed Jul 13, 2021
1 parent 9c2d854 commit 8c2bc76
Show file tree
Hide file tree
Showing 52 changed files with 852 additions and 0 deletions.
Binary file added FoodKart/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions FoodKart/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions FoodKart/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions FoodKart/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions FoodKart/FoodKart.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added FoodKart/out/production/FoodKart/enums/Gender.class
Binary file not shown.
Binary file added FoodKart/out/production/FoodKart/model/Comment.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added FoodKart/out/production/FoodKart/model/User.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
97 changes: 97 additions & 0 deletions FoodKart/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Foodkart:

Description:

Flipkart is starting a new online food ordering service. In this Service, users can order food from a restaurant which is serviceable in their area and the restaurant will deliver it.
Features:

Restaurants can only serve one specialized dish.
Restaurants can serve in multiple areas.
At a time, users can order from one restaurant, and the quantity of food can be more than one.
Users should be able to rate any restaurant with or without comment.
Rating of a restaurant is the average rating given by all customers.
Requirements:

Register a User:
register_user(user_details)

user_details: name, gender, phoneNumber(unique) and pincode.

Users should be able to login, and all the operations will happen in the context of that user. If another user logged in, the previous user will automatically be logged out.
login_user(user_id): this should set the context for all the next operation to be done by this user.
Register a restaurant in context of login user:
Register_restaurant(resturant_name, list of serviceable pin-codes, food item name, food item price, initial quantity).
Restaurant owners should be able to increase the quantity of the food item.
update_quantity(restaurant name, quantity to Add)
Users should be able to rate(1(Lowest)-5(Highest)) any restaurant with or without comment.
rate_restaurant(restaurant name, rating, comment)
User should be able to get list of all serviceable restaurant, food item name and price in descending order: show_restaurant(rating/price)
Based on rating
Based on Price
NOTE: A restaurant is serviceable when it delivers to the user's pincode and has non-zero quantity of food item.
Place an order from any restaurant with any allowed quantity.
place_order(restaurant name, quantity)
Bonus:
Order History of User: For a given user you should be able to fetch order history.
Other Details:
Do not use any database or NoSQL store, use in-memory store for now.
Do not create any UI for the application.
Write a driver class for demo purposes. Which will execute all the commands at one place in the code and test cases.
Please prioritize code compilation, execution and completion.
Please do not access the internet for anything EXCEPT syntax.
You are free to use the language of your choice.
All work should be your own. If found otherwise, you may be disqualified.
Expectations:
Code should be demoable (very important)
Complete coding within the duration of 90 minutes.
Code should be modular, with Object Oriented design. Maintain good separation of concerns.
Code should be extensible. It should be easy to add/remove functionality without rewriting the entire codebase.
Code should handle edge cases properly and fail gracefully.
Code should be readable. Follow good coding practices:
Use intuitive variable names, function names, class names etc.
Indent code properly.
Once the code is complete please zip the source code and upload it to: https://docs.google.com/forms/d/e/1FAIpQLSfzz8HH6fLso7NLgqJ0kC0TYP-tZhC2XhTN4EdI2c6OC1v2XA/viewform
Sample Test Case:
All the inputs here are just indicating the high level inputs that function should accept. You are free to model entities as per your choice.

register_user(“Pralove”, “M”, “phoneNumber-1”, “HSR”)
register_user(“Nitesh”, “M”, “phoneNumber-2”, “BTM”)
register_user(“Vatsal”, “M”, “phoneNumber-3”, “BTM”)

login_user(“phoneNumber-1”)

register_restaurant(“Food Court-1”, “BTM/HSR”, “NI Thali”, 100, 5)
NOTE: we will have 2 delimiters in input : ',' to specify separate fields & '/' to identify different pincodes.
register_restaurant(“Food Court-2”, “BTM”, “Burger”, 120, 3)

login_user(“phoneNumber-2”)
register_restaurant(“Food Court-3”, “HSR”, “SI Thali”, 150, 1)
login_user(“phoneNumber-3”)
show_restaurant(“price”)

Output : Food Court-2, Burger
Food Court-1, NI Thali

place_order(“Food Court-1”, 2)
Output: Order Placed Successfully.

place_order(““Food Court-2”, 7)
Output : Cannot place order

create_review(“Food Court-2”, 3, “Good Food”)
create_review(“Food Court-1”, 5, “Nice Food”)

show_restaurant(“rating”)
Output : Food Court-1, NI Thali
Food Court-2, Burger

login_user(“phoneNumber-1”)
update_quantity(“Food Court-2”, 5)
Output: Food Court-2, BTM, Burger - 8

update_location(“Food Court-2”, “BTM/HSR”)
Output: Food Court-2, “BTM/HSR”, Burger - 8



https://docs.google.com/document/d/1Bmkz9omByHqVvwU45cvkBRSwJAPKw9yaDsRlEnCg_lg/edit#
7 changes: 7 additions & 0 deletions FoodKart/src/Exceptions/RestaurantAlreadyPresent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Exceptions;

public class RestaurantAlreadyPresent extends RuntimeException {
public RestaurantAlreadyPresent(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions FoodKart/src/Exceptions/RestaurantNotPresent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Exceptions;

public class RestaurantNotPresent extends RuntimeException {
public RestaurantNotPresent(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions FoodKart/src/Exceptions/UserAlreadyPresent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Exceptions;

public class UserAlreadyPresent extends RuntimeException {
public UserAlreadyPresent(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions FoodKart/src/Exceptions/UserNotPresent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Exceptions;

public class UserNotPresent extends RuntimeException{
public UserNotPresent(String message) {
super(message);
}
}
53 changes: 53 additions & 0 deletions FoodKart/src/FoodKartApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import model.Restaurant;
import service.FoodKartRestaurantService;
import service.FoodKartRestaurantServiceImpl;
import service.FoodKartUserService;
import service.FoodKartUserServiceImpl;

import java.util.List;

public class FoodKartApplication {
public static void main(String[] args) {
FoodKartUserService userService = new FoodKartUserServiceImpl();
FoodKartRestaurantService restaurantService = new FoodKartRestaurantServiceImpl();

userService.registerUser("Pralove", "Male", "phoneNumber-1", "HSR");
userService.registerUser("Nitesh", "Male", "phoneNumber-2", "BTM");
userService.registerUser("Vatsal", "female", "phoneNumber-3", "BTM");

// login user
userService.loginUser("phoneNumber-1");

// register restaurant
restaurantService.registerRestaurant("Food Court-1", "BTM/HSR", "NI Thali", 100, 5);
restaurantService.registerRestaurant("Food Court-2", "BTM", "Burger", 120, 3);
restaurantService.registerRestaurant("Food Court-3", "HSR", "SI Thali", 150, 1);

userService.loginUser("phoneNumber-3");
List<Restaurant> list = restaurantService.showRestaurant("price");
for (Restaurant restaurant : list) {
System.out.println(restaurant.getRestaurantName() + " " + restaurant.getFoodItem().getName());
}

if(restaurantService.placeOrder("Food Court-1", 2)){
System.out.println("Order Placed Successfully");
}

if(!restaurantService.placeOrder("Food Court-2", 7)){
System.out.println("Cannot place order");
}


restaurantService.rateRestaurant("Food Court-2", 3, "Good Food");
restaurantService.rateRestaurant("Food Court-1", 5, "Nice Food");

list = restaurantService.showRestaurant("rating");
for (Restaurant restaurant : list) {
System.out.println(restaurant.getRestaurantName() + " " + restaurant.getFoodItem().getName());
}

userService.loginUser("phoneNumber-1");
restaurantService.updateQuantity("Food Court-2",5);

}
}
22 changes: 22 additions & 0 deletions FoodKart/src/Util/FoodKartUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package Util;

import model.Restaurant;
import model.User;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FoodKartUtil {
public static List<Restaurant> getMatchingRestaurant(List<Restaurant> listOfRestaurants, User currentUser) {
List<Restaurant> list = new ArrayList<>(listOfRestaurants);
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
Restaurant restaurant = (Restaurant) iterator.next();
if (!restaurant.isLocationServiceAble(currentUser.getPincode()) && restaurant.isEnoughQuantityAvailable()) {
iterator.remove();
}
}
return list;
}
}
10 changes: 10 additions & 0 deletions FoodKart/src/dao/OrderDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dao;

import model.Order;

import java.util.HashMap;

public class OrderDao {
HashMap<Integer, Order> listOfOrders;
HashMap<String, Order> userOrderMap;
}
Loading

0 comments on commit 8c2bc76

Please sign in to comment.