你說(shuō)的這個(gè)程序應(yīng)該是不難的,只不過(guò)N久沒(méi)有寫(xiě)過(guò)javaswing 了
創(chuàng)新互聯(lián)建站是一家專(zhuān)業(yè)提供尋甸企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為尋甸眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
還有就是java沒(méi)有多繼承的,只有多實(shí)現(xiàn)接口的
繼承的關(guān)鍵字是:extends
接口的關(guān)鍵字是:interface
public class SaleTicket extends Thread{
static int mark=0;
static int ticket[]=new int [100];
int SaleTicketNo;
SaleTicket(int num){
SaleTicketNo=num;
}
public void run() {
// compute primes larger than minPrime
for(int i=0;i100;i++)
{
if(ticket[i]==0){
ticket[i]=1;
mark=mark+1;
System.out.println("售票機(jī)編號(hào):"+SaleTicketNo+" 票號(hào):"+i+" 張次:"+mark);
}
}
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
SaleTicket sale1=new SaleTicket(101);
SaleTicket sale2=new SaleTicket(102);
SaleTicket sale3=new SaleTicket(103);
SaleTicket sale4=new SaleTicket(104);
SaleTicket sale5=new SaleTicket(105);
sale1.start();
sale2.start();
sale3.start();
sale4.start();
sale5.start();
}
}
不考慮死鎖問(wèn)題
package?tmp;
public?class?Test?{
private?static?int?k=0;//售出票數(shù)
private?static?int?count=1000;//總票數(shù)
private?static?synchronized?boolean?sell(int?n){
if(kcount){
k++;
System.out.println("第"+n+"售票點(diǎn)售出第"+k+"張票");
return?true;
}
return?false;
}
static?class?SellPot?extends?Thread{//售票點(diǎn)
int?n;//售票點(diǎn)編號(hào)
public?SellPot(int?n){
this.n=n;
}
public?void?run(){
while(sell(n)){
try?{
Thread.sleep(100);
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
}
}
public?static?void?main(String[]?args)?{
for(int?i=1;i=10;i++){
new?SellPot(i).start();
}
}
}
//銀行匯款
public?class?Test2?{
private?static?int?k=0;//總匯款
private?static?synchronized?void?send(int?m,int?i,int?n){
k+=m;
System.out.println("第"+n+"個(gè)顧客進(jìn)行第"+(i+1)+"次匯款,銀行接收總匯款"+k);
}
static?class?Costum?extends?Thread{//售票點(diǎn)
int?n;//顧客編號(hào)
public?Costum(int?n){
this.n=n;
}
public?void?run(){
for(int?i=0;i3;i++){
send(100,i,n);//匯款100
try?{
Thread.sleep(100);
}?catch?(InterruptedException?e)?{
e.printStackTrace();
}
}
}
}
public?static?void?main(String[]?args)?{
for(int?i=1;i=3;i++){
new?Costum(i).start();
}
}
}