Giter VIP home page Giter VIP logo

bikefactory's Introduction

#bikeFactory 题目要求: 1、使用面向对象**,编写程序描述摩托车、电动车、单车的属性和行为。 说明:属性有颜色、高度、名称;行为有启动、前进、响喇叭 2、基于上一题,编写程序描述单车工厂、单车售卖商店。 条件: (1)实现1个单车工厂类,1个单车售卖商店类(一个类new 两个实例),1个单车类 (2)各个商店每20秒向工厂申请5辆单车(工厂库存不足5辆就给出剩余的单车,不阻塞线程) ,商店有自己的库存(即装单车的集合)。 (3)商店随机时间(1秒到10秒)会卖出一辆单车,当商店单车库存为零时工厂会马上工厂申请5辆单车。 (提示:工厂库存不足5辆就给出剩余的单车,此时工厂如果库存为0则会阻塞线程等待工厂生产单车,商店类中有2个线程,线程1用于向工厂申请单车,线程2用于单车销售。) (4)工厂会每2秒生产一辆单车,有自己的库存(即装单车的集合)。 补充:工厂线程先运行8秒钟后再运行商店线程,商店库存为0时停止销售单车;并向工厂申请单车直到申请成功库存>0时再开始销售 要求:实现时用好面向对象**,代码要整洁可读性良好,结构要考虑可扩展性。

反思代码的不足之处: 数据结构不应该用链表,应该用普通的数组加锁,wait notify来控制;或者用java的阻塞队列,现在的代码没有阻塞等待生产的能力;如果商店没有单车卖会一直死循环,这样比较浪费资源。

bikefactory's People

Contributors

bxh7425014 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.