import java.util.Random; public class z { public static void main(String[] args) { Worker worker=new Worker(); Ys ys=new Ys(); try { worker.work(); } catch (jkzkException e) { ys.cure(worker); if(worker.getStatus().equals("健康")){ System.out.println("恭喜你健康了"); }else { System.out.println("00000000尽力了"); } }finally{ System.out.println("欢迎下次再来"); } } } class Worker{ private String status; public void satStatus(String status){ this.status=status; } public String getStatus(){ return status; } public void work()throws jkzkException{ Random random=new Random(); int rad=random.nextInt(3)+1; if(rad==1){ throw new jkzkException("你有病 "); }else{ System.out.println("身体健康不用治疗"); } } } class jkzkException extends Exception{ -精品- private String messae; public jkzkException(String messae){ this.messae=messae; } public String getMessage(){ return messae; } } class Ys{ public void cure(Worker worker){ Random random=new Random(); int rad=random.nextInt(2)+1; if(rad==1){ worker.satStatus("健康"); }else{ worker.satStatus("死亡"); } } } -精品- 本文来源:https://www.wddqw.com/doc/e71487831611cc7931b765ce05087632311274ad.html