代写CSI3131作业、代写Java编程语言作业、Java课程设计作业代做、代做Java semaphores作业代做留学生Processing|代写R语言程

CSI3131 – Lab3Thread Synchronization (Java)ObjectivesTo gain experience with Java semaphores in creating a simulation of a ferry that services automobilesand an ambulance. Read the lab document carefully before starting. The FerryThe ferry offers services between two ports, port 0 and port 1. Automobiles travel between thesetwo ports, as well as ambulance(s). Each automobile arrives at a port, boards the ferry (when itarrives at the port), crosses to the other port, disembarks the ferry, travels around for a bit, and thengoes back to the port to cross again.The ambulance is a vehicle (the automobiles and ambulance are both vehicles) that functions like theautomobile with the exception: when an ambulance boards the ferry, the ferry leaves immediatelywithout waiting to be full.The ferry travels between the two ports (0 and 1): when it arrives at a port, vehicles on boarddisembark first, then any waiting vehicles board. When the ferry is full, or an ambulance boards, itleaves for the other port.The provided java code Lab4.java contains 5 classes as follows: - Class FerryApp is a console application that create the Ferry and all automobiles in thesimulation- Class Auto simulates a single automobile thread- Class Ambulance simulates a single ambulance thread- Class Ferry simulates the ferry thread- Interface Logger that is used to assert correct operation of the ferryTo compile and run the simulation: - javac *.java- java FerryApp, or java -ea FerryAppo (ea or Enable Assertion is used to assert the proper operation of the ferry, with thisflag enable the application will generate exceptions when an error is detected. Use thisflag before submitting your lab to make sure your solution works fine)You may pipe the output to a file for further analysis as follows (Linux only?!): - java FerryApp | tee tmp.txtNotesNotice when you run the simulation there are going to be a lot of violations due to threadsynchronization errors! Your task is to add the proper thread synchronization constructs to obey allthe rules of the ferry simulation and have no errors as a result.Your simulation must meet the following Rules:1.The maximum capacity of the ferry is 5 vehicles. 2.A vehicle at port “p” boards the ferry ifa. The ferry is at the same port p,b. All vehicles that arrived with the ferry on board have all disembarked the ferry, andc. There still exists room on the ferry for the vehicle.3.A vehicle at port ? p ? must waita. If the ferry is not at the same port ? p ?,b. Vehicles are disembarking from the ferry,c. The ferry is full and is ready to leave.4.If an ambulance boards the ferry, the ferry leaves immediately.5.If the ferry is not full and with no ambulance on board, it waits for other automobiles to arrive.6.A vehicle can disembark only at the arrival at the next port.The above rules are checked in the code, you must leave all checks as is. The checks are going to beused to verify your solution.Your TaskYour task is to modify the Auto, Ambulance, and Ferry classes by adding semaphore constructs to theFerry class that will make the ferry simulation pass all the ferry rules without any error.GuidelinesYou can use the following guidelines: - The single Ferry object is visible in all other threads, thus it is an ideal candidate to hold all therequired semaphores for simulation- The addLoad, reduceLoad, loadAmbulance, unloadAmbulance methods should be mutuallyexclusive. You can use the intrinsic locks for that – see the lecture slides about intrinsic locks- The Ferry needs 2 semaphores, namely loadingDone, unloadingDone, to wait for vehicles tobe loaded before starting a crossing, and then waiting for vehicles to unload before allowingvehicles to load- Vehicles (Auto, Ambulance) needs loadingSemaphore and unloadingSemaphore on each port(i.e. array of 2 each) to synchronize the loading/unloading of vehicles on each port- When you provide a handle for InterruptedException, use the following code snip-it to let theapplication terminate gracefully:try {////// your code here ///////} catch (InterruptedException ie) {Thread.currentThread().interrupt();System.out.println(Thread terminated by interruption);// handle the interruptreturn;}When the Ferry is docking on port0 the situation looks like the following:First the ferry signals the loading on port0, then waits for loading done, makes the crossing and thensignals the unloading on port1, followed by a wait for unloading done. This finishes one loop of theferry crossing.Meanwhile, the vehicles on both sides are waiting to load on that port, then waits to unload on theopposite port after the ferry completes the crossing. The difference between the Ambulance andAuto is that the ambulance makes sure no other Auto is allowed to board after it by draining thepermits (see Java Semaphore drainPermits) of the loading semaphore after entering it.What is left is the events to signal the loadingDone, and unloadingDone semaphores, which can beeasily detected in the addLoad, reduceLoad, loadAmbulance, unloadAmbulance methods of theferry.When the Ferry is docking on port1 the situation looks like the following:Submission NoteYour code must compile & run to get the full mark. We’re going to use other scenarios (number ofcrossings, autos, ambulances) to verify your solution. A bug free solution will support any scenario.本团队核心人员组成主要包括BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected] 微信:codehelp

QQ:99515681 或邮箱:[email protected] 微信:codehelp

你可能感兴趣的:(代写CSI3131作业、代写Java编程语言作业、Java课程设计作业代做、代做Java semaphores作业代做留学生Processing|代写R语言程)