91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 33KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-05-07
  • 語(yǔ)言: Java
  • 標(biāo)簽: JAVA??多線程??

資源簡(jiǎn)介

CD租售店 請(qǐng)實(shí)現(xiàn)一個(gè)CD出租銷售店的模擬程序,該CD租售店,具有可租cd列表,可售cd列表。并具有租、還cd,銷售、進(jìn)貨CD方法。假設(shè)cd店中可租CD列表5張,可售CD列表5種,每種10張,請(qǐng)實(shí)現(xiàn)以下線程 進(jìn)貨線程:只有一個(gè),固定的每1秒啟動(dòng)一次,但是如果臨時(shí)缺貨則購(gòu)買線程發(fā)送消息緊急啟動(dòng)一次,每次補(bǔ)齊可售CD列表。 銷售線程:可以有兩個(gè)或兩個(gè)以上,啟動(dòng)的時(shí)間為500ms以內(nèi)的隨機(jī)數(shù)。購(gòu)買數(shù)量為5以內(nèi)的隨機(jī)數(shù)。如果cd數(shù)量不足則隨機(jī)選擇等候或放棄。 租借線程:租借CD店的可租借CD,啟動(dòng)時(shí)間為300ms以內(nèi)的隨機(jī)數(shù)。租借序號(hào)為1-5隨機(jī)序號(hào)的CD,如果該CD已經(jīng)出租則隨機(jī)選擇等候或者放棄。如果可以借到CD則隨機(jī)等候200~300ms然后歸還。 程序運(yùn)行2分鐘以后停止。最后列出購(gòu)買、進(jìn)貨、租借還的紀(jì)錄(時(shí)間及行為)。 程序運(yùn)行兩次,以record.txt方式提交兩次的程序輸出。 提交源程序。

資源截圖

代碼片段和文件信息

package?lab4;
import?java.util.ArrayList;
import?java.util.Date;
import?java.util.Random;
import?java.io.File;
import?java.io.FileOutputStream;
import?java.io.IOException;
import?java.io.PrintStream;
class?SaleCD
{
int?cdid;
String?name;
int?count;
public?SaleCD(int?cdid?String?name?int?count)?{
super();
this.cdid?=?cdid;
this.name?=?name;
this.count?=?count;
}

}
class?RentCD
{
int?cdid;
String?name;
boolean?isRent;

public?RentCD(int?cdid?String?name?boolean?isRent)?{
super();
this.cdid?=?cdid;
this.name?=?name;
this.isRent?=?false;
}

}
class?InputThread?extends?Thread{
ArrayList?SaleList;
MyCDshop?cdshop;
public?InputThread(MyCDshop?cdshop){
super();
this.cdshop?=?cdshop;
}

}
class?SaleThread?extends?Thread
{

ArrayList?SaleList;
MyCDshop?cdshop;

public?SaleThread(MyCDshop?cdshop)?{
super();
this.cdshop?=?cdshop;
}
@Override
public?void?run()?{
while(true)
{
try?{
sleep((int)(Math.random()*500));
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
int?cdid=(int)(Math.random()*5)+1;
int?cdcount=(int)(Math.random()*5)+1;
synchronized?(cdshop.SaleList)?{
if?(cdshop.saleCD(cdid?cdcount))?{
System.out.println(new?Date()+“成功銷售“?+?cdid?+?“數(shù)量“?+?cdcount);
}?else?{
Random?r?=?new?Random();
if?(r.nextBoolean())?{
System.out.println(new?Date()+“數(shù)量不足,等候“);
cdshop.SaleList.notify();
do
{
try?{
cdshop.SaleList.wait();
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
while(!cdshop.saleCD(cdid?cdcount));
System.out.println(new?Date()+“等候以后“+“成功銷售“?+?cdid?+?“數(shù)量“?+?cdcount);

}
else
{
System.out.println(new?Date()+“放棄銷售“);
cdshop.SaleList.notify();
}
}
}
}
}
}
class?RentThread?extends?Thread
{
MyCDshop?cdshop;
public?RentThread(MyCDshop?cdshop)?{
super();
this.cdshop?=?cdshop;
}
@Override
public?void?run()?{
while(true)
{
try?{
sleep((int)(Math.random()*300));
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
int?cdid=(int)(Math.random()*5+1);
int?times=(int)(Math.random()*100)+200;
synchronized?(cdshop.RentList)?{
if?(cdshop.rentCD(cdid-1))?{
System.out.println(new?Date()+“成功租到“?+?“編號(hào)“+?cdid??);
try{
Thread.sleep(times);
}catch(InterruptedException?e)?{
e.printStackTrace();
}
cdshop.backCD(cdid);
System.out.println(new?Date()+“歸還“?+cdid);
}?
else?{
Random?r?=?new?Random();
if?(r.nextBoolean())?{
System.out.println(new?Date()+“已租出,等候“);
cdshop.RentList.notify();
do
{
try?{
cdshop.RentList.wait();
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
while(cdshop.rentCD(cdid-1));

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-12-22?19:47??Cd\
?????文件?????????301??2015-12-06?10:30??Cd\.classpath
?????文件?????????378??2015-12-06?10:30??Cd\.project
?????目錄???????????0??2015-12-22?19:45??Cd\.settings\
?????文件?????????598??2015-12-06?10:30??Cd\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2015-12-22?19:45??Cd\bin\
?????目錄???????????0??2015-12-22?19:45??Cd\bin\lab4\
?????文件?????????811??2015-12-22?19:36??Cd\bin\lab4\ControlThread.class
?????文件????????1299??2015-12-22?19:36??Cd\bin\lab4\GetInThread.class
?????文件?????????456??2015-12-22?19:36??Cd\bin\lab4\InputThread.class
?????文件????????3183??2015-12-22?19:36??Cd\bin\lab4\MyCDshop.class
?????文件?????????448??2015-12-22?19:36??Cd\bin\lab4\RentCD.class
?????文件????????2184??2015-12-22?19:36??Cd\bin\lab4\RentThread.class
?????文件?????????443??2015-12-22?19:36??Cd\bin\lab4\SaleCD.class
?????文件????????1992??2015-12-22?19:36??Cd\bin\lab4\SaleThread.class
?????文件????????6907??2015-12-22?19:33??Cd\record.txt
?????目錄???????????0??2015-12-22?19:45??Cd\src\
?????目錄???????????0??2015-12-22?19:45??Cd\src\lab4\
?????文件????????6427??2015-12-22?19:36??Cd\src\lab4\MyCDshop.java
?????文件???????23872??2016-11-25?16:16??CD租售店.docx

評(píng)論

共有 條評(píng)論