Hw06 of CS61A of UCB
作者:互联网
OOP
Q1: Vending Machine
In this question you'll create a vending machine that only outputs a single product and provides change when needed.
Create a class called
VendingMachine
that represents a vending machine for some product. AVendingMachine
object returns strings describing its interactions. Remember to match exactly the strings in the doctests -- including punctuation and spacing!Fill in the
VendingMachine
class, adding attributes and methods as appropriate, such that its behavior matches the following doctests:
According to the wiki, a vending machine is an automated machine that provides items to consumers after cash, or other forms of payment are inserted into the machine or otherwise made
这里说的 vending machine 其实也就是常见的自动售货机, 我们要为其写一个类实现应该有的功能. 这里的要求更为简单, 因为我们要实现的自动售货机只有一样东西可以卖, 而且每次只会买一件. 注意下面要实现函数的逻辑即可: