Wayfair Coding round - SDE II

Anonymous User
898
Jul 08, 2024
Jul 08, 2024

I was asked to implement below coding problem.

Description
An order management system for a restaurant is being developed. Implement the OrderSystem class and the IOrderSystem interface as described.

The IOrder interface contains the methods that the Order class should implement.

Add the following properties to the class:
name (String)
price (int)

Create a new class called OrderSystem and implement the IOrderSystem interface.

Implement the following methods:
addToCart(IOrder order): add the order item to the cart
removeFromCart(IOrder order): remove the order item from the cart

calculateTotalAmount(): calculate the discounted prices for each order in the cart and sum the values

categoryDiscounts(): Calculate discounts for each product category in the cart. First, group the products in the basket according to category, then sum the discounted prices for each group. The discounted price calculation is shown as Discounted Price = Order Price - ((Order Price * Discount Rate) % 100). The method returns a map of categories name and the discount amount. (key = category, value = category discount)

cartItems(): This method retrieves the list of items in the cart along with their quantities. It groups the products by their names and counts the number of products ordered for each group. The method returns this map of names of items in the cart and their quantities. (key = name, value = item count)

Category determination is done as follows:

Order Price <= 10: Cheap
Order Price <= 20 and OrderPrice > 10: Moderate
Order Price > 20 and OrderPrice > 20: Expensive
The discount per category is as follows:

Cheap = 10%
Moderate = 20%
Expensive = 30%

Example

There are 2 Order objects, with name, price:

Television 40

Computer 30

After they are added, calculate the total amount from orders.

e.g. The Price for Television = 40 and 40 > 20, so the discount equals 30%. The discounted price = 40 - ((40*30)/100) = 28. Similarly, the 30% discounted price of Computer is 21.

Output:

Total Amount: 49

Expensive Category Discount: 49

Television (1 items)

Computer (1 items)

Input Format For Custom Testing
The first line contains an integer n, the number of orders.

Each of the next n lines contains the order information separated by space (name price).

Sample Case 1
Sample Input For Custom Testing

STDIN Function


9 number of orders n = 9
Order-1 49 first order: name = 'Order-1', price = 49
Order-2 31 second order...
Order-3 74
Order-4 21
Order-5 64
Order-6 94
Order-7 23
Order-8 23
Order-9 71
Sample Output

Total Amount: 319
Expensive Category Discount: 131
Order-1 (1 items)
Order-2 (1 items)
Order-3 (1 items)
Order-4 (1 items)
Order-5 (1 items)
Order-6 (1 items)
Order-7 (1 items)
Order-8 (1 items)
Order-9 (1 items)
Explanation

9 orders are added and grouped by price category. All items are in the 'Expensive' category, so only 1 group of items is reported. Data is read, method calls are made, and results are printed by the provided stub.

Comments (5)