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