java检查危险品程序_危险品检查java程序

我的源代码:publicenumExample{雷管,炸药,硫酸,面包,薯片,洗面奶}publicclassIntegerExceptionextendsException{Stringmessage;publicIntegerException(Stringm){message="检查物品:"...

我的源代码:

public enum Example{

雷管,炸药,硫酸,面包,薯片,洗面奶

}

public class IntegerException extends Exception{

String message;

public IntegerException (String m){

message="检查物品:"+ m +"危险物品不予通过!";

}

public String toString(){

return message;

}

}

public class Goods{

private String goods;

public void setGoods (String goods) throws IntegerExpection {

if (goods = Example.雷管 || goods = Example.炸药 || goods = Example.硫酸){

throw new IntegerException(goods);

}

else{

this.goods=goods;

}

public String getGoods(){

System.out.println("检查物品:"+goods+"普通物品允许通过!");

return goods;

}

}

public class exer5{

public static void main (String args[]){

Goods S1 = new Goods();

Goods S2 = new Goods();

Goods S3 = new Goods();

Goods S4 = new Goods();

Goods S5 = new Goods();

Goods S6 = new Goods();

try { S1.setGoods(雷管);

System.out.println(S1.getGoods);

}

catch(IntegerException e){

System.out.println(e.toString);

}

try { S2.setGoods(炸药);

System.out.println(S2.getGoods);

}

catch(IntegerException e){

System.out.println(e.toString);

}

try { S3.setGoods(硫酸);

System.out.println(S3.getGoods);

}

catch(IntegerException e){

System.out.println(e.toString);

}

try { S4.setGoods(洗面奶);

System.out.println(S4.getGoods);

}

catch(IntegerException e){

System.out.println(e.toString);

}

try { S5.setGoods(面包);

System.out.println(S5.getGoods);

}

catch(IntegerException e){

System.out.println(e.toString);

}

try { S6.setGoods(薯片);

System.out.println(S6.getGoods);

}

catch(IntegerException e){

System.out.println(e.toString);

}

}

}

有些冗长,求指点,感激不尽,

展开

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值