概述
我的源代码: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);
}
}
}
有些冗长,求指点,感激不尽,
展开
最后
以上就是顺利纸鹤为你收集整理的java检查危险品程序_危险品检查java程序的全部内容,希望文章能够帮你解决java检查危险品程序_危险品检查java程序所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复