ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Hw06 of CS61A of UCB

2022-02-27 16:01:08  阅读:194  来源: 互联网

标签:node return Hw06 self list CS61A UCB year def


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

        本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
        2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
        3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
        4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
        5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有