• 异常的最后练习


    /*
     我们来练习一下一个人用电脑办公,电脑突然停电了
     这有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());
      } 
     }
    }

  • 相关阅读:
    旅行
    赛道修建
    逃学的小孩
    hdu4035_概率dp
    hdu4405_概率dp
    poj2096_概率dp
    poj3420_找规律+矩阵快速幂
    poj2411_状压dp
    poj3744_矩阵快速幂
    hdu5720_贪心
  • 原文地址:https://www.cnblogs.com/daoxiang1992/p/5693020.html
Copyright © 2020-2023  润新知