速配婚姻介绍所,每次执行都有不同的结果呦!

来源:互联网 发布:网络监控摄像头安装 编辑:程序博客网 时间:2024/04/28 21:50
public class Partner{
public static void main(String[] args){
MatchMarry group1=new MatchMarry("曹操","传明");
MatchMarry group2=new MatchMarry("小六","小慧");
MatchMarry group3=new MatchMarry("小花","小二货");
MatchMarry group4=new MatchMarry("曹操","小花");
MatchMarry group5=new MatchMarry("传明","小六");
System.out.println("**速配婚姻介绍所,宗旨是要保证发扬\"执子之手 与子偕老\"的精神");
group1.start();
try{
group1.join();
}catch(InterruptedException e){
System.out.println("唤醒异常:"+e.getMessage());
}
group2.start();
try{
group2.join();
}catch(InterruptedException e){
System.out.println("唤醒异常:"+e.getMessage());
}
group3.start();
try{
group3.join();
}catch(InterruptedException e){
System.out.println("唤醒异常:"+e.getMessage());
}
group4.start();
try{
group4.join();
}catch(InterruptedException e){
System.out.println("唤醒异常:"+e.getMessage());
}
group5.start();
try{
group5.join();
}catch(InterruptedException e){
System.out.println("唤醒异常:"+e.getMessage());
}
System.out.println("速配结束...");
}
}
class MatchMarry extends Thread{
private String name;
private String otherName;
private boolean isMarry=false;
public MatchMarry(String name,String otherName){
this.name=name;
this.otherName=otherName;
}
public void run(){
try{
int person=(int)Math.floor((Math.random()*10+1));
if (person%2==0){
isMarry=true;
}
else{
isMarry=false;
}
if(!isMarry){
System.out.println(name+"可以与"+otherName+"结婚,祝福你们");
}else{
System.out.println(otherName+"已婚,红色警告:对待婚姻不要有二心");
}
Thread.sleep(200);
}catch(InterruptedException e){
System.out.println("唤醒异常:"+e.getMessage());
}
}

}


原创粉丝点击