其他分享
首页 > 其他分享> > Hw06 of CS61A of UCB

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. A VendingMachineobject 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 其实也就是常见的自动售货机, 我们要为其写一个类实现应该有的功能. 这里的要求更为简单, 因为我们要实现的自动售货机只有一样东西可以卖, 而且每次只会买一件. 注意下面要实现函数的逻辑即可:

  1. restock, 补充商品, 这个比较简单
  2. add_funds
    1. 商品有库存的时候才会记住你付了多少钱
    2. 商品没有库存的时候直接退款给你
  3. vend
    1. 商品有库存的时候
      1. 你支付的钱

        标签:node,return,Hw06,self,list,CS61A,UCB,year,def
        来源: https://www.cnblogs.com/MartinLwx/p/15942547.html