import Java.util.ArrayList;
interface Stuff{}
//矿石
interface Ore extends Stuff{}
//武器
interface Weapon extends Stuff{}
//垃圾
interface Rubbish extends Stuff{}
//金矿
class Gold implements Ore{
public String toString(){
return "Gold";
}
}
//铜矿
class Copper implements Ore{
public String toString(){
return "Copper";
}
}
//枪
class Gun implements Weapon{
public String toString(){
return "Gun";
}
}
//榴弹
class Grenade implements Weapon{
public String toString(){
return "Grenade";
}
}
class Stone implements Rubbish{
public String toString(){
return "Stone";
}
}
public class Test{
public static ArrayList<Stuff> collectStuff(Stuff[] s){
ArrayList<Stuff> al=new ArrayList<Stuff>();
for(int i=0;i<s.length;i++){
if(!(s[i] instanceof Rubbish))
al.add(s[i]);
}
return al;
}
public static void main(String[] args){
Stuff[] s={new Gold(),new Copper(),new Gun(),new Grenade(),new Stone()};
ArrayList<Stuff> al=collectStuff(s);
System.out.println("The usefull Stuff collected is:");
for(int i=0;i<al.size();i++)
System.out.println(al.get(i));
}
}
人爱美,不仅需要服饰居室之美,还需要心灵品德之美。