Coding problem
A summary line for each order
The task
The orders page shows one summary line for each order, the most valuable orders first.
Complete Summarise(List<Order> orders). An Order is a record with an Id, a Customer and its Lines; a Line has a Product, a Quantity and a UnitPrice. Return one OrderSummary for each order: Items is the total quantity of its lines, and Total is the sum of Quantity times UnitPrice over its lines. Put the biggest Total first; orders with the same total are sorted by Id, smallest first. An order with no lines gets 0 items and a total of 0. An empty list gives an empty list. The lists, orders and lines are never null, ids are unique, and quantities and prices are 0 or more.
Signature
public record Line(string Product, int Quantity, decimal UnitPrice); public record Order(int Id, string Customer, List<Line> Lines); public record OrderSummary(int Id, string Customer, int Items, decimal Total); public static List<OrderSummary> Summarise(List<Order> orders)
Examples
[(1, "amy", [("pen", 2, 1.50)]), (2, "ben", [("desk", 1, 120.00), ("lamp", 2, 15.00)])]→[(2, "ben", 3, 150.00), (1, "amy", 2, 3.00)]. Order 2 has 1 + 2 = 3 items worth 120 + 30 = 150, so it comes first.[(7, "cara", [])]→[(7, "cara", 0, 0)]. An order with no lines still gets a summary, with nothing in it.
Limits: Up to 100,000 orders with up to 10 lines each.
The tests check: an empty list, an order with no lines, items adding up quantities rather than lines, each line multiplied before adding, the total deciding before the id, equal totals sorted by id, each summary keeping its customer, and 100,000 orders in time.
Hints
The solution opens by itself when all tests pass. You remember more if you try first.
Sign in to see the solutionYour code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public record Line(string Product, int Quantity, decimal UnitPrice);
public record Order(int Id, string Customer, List<Line> Lines);
public record OrderSummary(int Id, string Customer, int Items, decimal Total);
public static class Solution
{
// One summary per order: its item count and total, the biggest total first, then by id.
public static List<OrderSummary> Summarise(List<Order> orders)
{
throw new NotImplementedException();
}
}Sign in to run and submit your code. It stays here while you do.