zoukankan      html  css  js  c++  java
  • 异常的最后练习

    /*
     我们来练习一下一个人用电脑办公,电脑突然停电了
     这有2个类 一个是人,一个是电脑 办公是人的动作
    */
    class Computer{
     private  int stic=2;
     void run()throws TingException,maoyanException{
      if(stic==1){
       throw new TingException("卡机了") ;
      }if(stic==2){
       throw new maoyanException("电脑冒烟");
      }
      else{ 
       System.out.println("电脑正在运行中");
      }
     }
     void problem(){
      System.out.println("修一下电脑");
     }
    }
    class TingException extends Exception{
     TingException(){
      super();
     }
     TingException(String message){
      super(message);
     }
    }
    class maoyanException extends Exception{
     maoyanException(){
      super();
     }
     maoyanException(String message){
      super(message);
     }
    }
    class nojueException extends Exception{
     nojueException(){
      super();
     }
     nojueException(String message){
      super(message);
     }
    }
    abstract class Person{
     public String name;
     public Computer c;
     Person(){};
     Person(String name){
      this.name=name;
      c=new Computer();
     }
     abstract void teach()throws nojueException; 
    }
    class WorkMan extends Person{
     WorkMan(){};
     WorkMan(String name){
      super(name);
     }
     void teach()throws nojueException{
      try{
       c.run();
      }
      catch(TingException t){
       System.out.println(t.getMessage());
       c.problem();
       
      }catch(maoyanException e){
       throw new nojueException("工作人员无法解决");
      }
      System.out.println(name+"上课"); 
     }  
    }
    public class text27{
     public static void main(String[] args){
      WorkMan worker=new WorkMan("小明");
      try{
       worker.teach();
      }catch(nojueException e){
       System.out.println(e.getMessage());
      } 
     }
    }

  • 相关阅读:
    Android Service组件在新进程绑定(bindService)过程
    第二章:创建框架和窗体
    ZOJ 2859 二维RMQ(模板)
    POJ 2828 Buy Tickets
    管理案例:怎样提高项目周例会的效率和效果?
    hdu4416 Good Article Good sentence (后缀数组)
    购买DigtalOcean VPS 安装Wordpress 攻略
    Asteroids!-裸的BFS
    hdu3015 Disharmony Trees
    iOS开发-自己定义后台显示图片(iOS7-Background Fetch的应用)
  • 原文地址:https://www.cnblogs.com/daoxiang1992/p/5693020.html
Copyright © 2011-2022 走看看