PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/ZipHQ

Implement a Vending Machine

Last updated: May 24, 2026

Quick Overview

This question evaluates object-oriented design, stateful transaction management, inventory control, and algorithmic change-making under resource constraints.

  • medium
  • ZipHQ
  • Software Engineering Fundamentals
  • Software Engineer

Implement a Vending Machine

Company: ZipHQ

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

Design and implement the core logic for a vending machine using object-oriented principles. The machine stores products, accepts bills, tracks the current customer's balance, dispenses an item after selection, and returns change. Requirements: - Each product has an id, a price in cents, and a remaining quantity. - The machine accepts a fixed set of bill denominations, for example 1, 5, 10, and 20 dollar bills. - `insertBill(amount)` adds money to the current transaction. - `selectProduct(productId)` should: 1. verify the product exists and is in stock, 2. verify the customer has inserted enough money, 3. deduct one unit of inventory, 4. compute and dispense change using bills available in the machine, 5. fail gracefully if exact change cannot be made. - `cancel()` should return the customer's inserted money and reset the transaction. - The implementation should be testable, and you should write tests for key cases such as insufficient funds, exact payment, overpayment, out-of-stock items, and inability to make exact change. Assume starter code is provided for the main classes, and implement the missing behavior and tests.

Quick Answer: This question evaluates object-oriented design, stateful transaction management, inventory control, and algorithmic change-making under resource constraints.

ZipHQ logo
ZipHQ
Jan 28, 2026, 12:00 AM
Software Engineer
Technical Screen
Software Engineering Fundamentals
19
0

Design and implement the core logic for a vending machine using object-oriented principles.

The machine stores products, accepts bills, tracks the current customer's balance, dispenses an item after selection, and returns change.

Requirements:

  • Each product has an id, a price in cents, and a remaining quantity.
  • The machine accepts a fixed set of bill denominations, for example 1, 5, 10, and 20 dollar bills.
  • insertBill(amount) adds money to the current transaction.
  • selectProduct(productId) should:
    1. verify the product exists and is in stock,
    2. verify the customer has inserted enough money,
    3. deduct one unit of inventory,
    4. compute and dispense change using bills available in the machine,
    5. fail gracefully if exact change cannot be made.
  • cancel() should return the customer's inserted money and reset the transaction.
  • The implementation should be testable, and you should write tests for key cases such as insufficient funds, exact payment, overpayment, out-of-stock items, and inability to make exact change.

Assume starter code is provided for the main classes, and implement the missing behavior and tests.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More ZipHQ•More Software Engineer•ZipHQ Software Engineer•ZipHQ Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.