Cloudkitchen / VO 面试真题解析:实现 Point-of-Sale Order 显示更新

18次阅读
没有评论

The self-service point-of-sale system you are implementing is a customer-facing touch-screen kiosk, positioned in a fast-food restaurant for customers to build their order. Customers select various menu items and are continuously presented with the state of their order: a list of items with their prices, and the total cost of the order.

For this part, you are asked to implement the userSelectedItem method, as it manipulates the active order (Order class) and calls the Display object.

Requirements are:

  • Assume that when the customer selects an item, your userSelectedItem method gets invoked by the system.
  • The textual display must be updated to reflect the current state of the customer’s order within each call to userSelectedItem.
  • Include a list of items, their quantities, the price of each line item, and the total price.

Example: when a user has selected two hamburgers ($6 each), fries ($3), and soda ($2), the display should show:

2x hamburger 12.0
1x fries 3.0
1x soda 2.0
Total: 17.0

(Note: the order of lines is not a requirement)

这道题考察的是一个点餐终端中的订单状态维护与文本渲染:每次用户选择菜单项时,系统需要在 `userSelectedItem` 中更新当前 `Order`,统计每种商品的数量,并按“数量 × 单价”计算每一行的小计,最后把完整订单和总价通过 `Display.render` 输出。实现时最关键的是用字典或计数结构维护商品累计数量,并在每次选择后重新生成展示文本;样例中两份 hamburger、一份 fries 和一份 soda,应输出各自小计以及总价 17.0。

正文完
 0