package storecrime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class CrimeTest {
public List CrimenameToSelect;
public CrimeTest() {
this.CrimenameToSelect=new ArrayList();
}
public void CrimenameAdd() {
crimename cn1=new crimename("乱扔垃圾","001",2);
CrimenameToSelect.add(cn1);
System.out.println("录入了罪名:"+cn1.rank+"级"+cn1.ID+""+cn1.name);
crimename cn2=new crimename("偷看室友洗澡","002",3);
System.out.println("录入了罪名:"+cn2.rank+"级"+cn2.ID+""+cn2.name);
//很有可能错在这里
crimename[] crimename2= {new crimename("考查课作弊","003",1),new crimename("考试课作弊","004",5)};
CrimenameToSelect.addAll(Arrays.asList(crimename2));
crimename temp1=(crimename)CrimenameToSelect.get(2);
crimename temp2=(crimename)CrimenameToSelect.get(3);
名:"+temp1.rank+"级"+temp1.ID+""+temp1.name+""+temp2.rank+"级"+temp2.ID+""+temp2.name);
}
public void testGet() {
int size=CrimenameToSelect.size();
System.out.println("存入以下罪刑:");
for(int i=0;i<size;i++) {
crimename cr=(crimename)CrimenameToSelect.get(i);
System.out.println("罪刑:"+cr.ID+":"+cr.name);
}
}
public void testIterator() {
Iterator it=CrimenameToSelect.iterator();
System.out.println("已存入以下罪刑(Iterator):");
while(it.hasNext()) {
crimename cr3=(crimename)it.next();
System.out.println("罪刑:"+cr3.ID+":"+cr3.name);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CrimeTest ct1=new CrimeTest();
ct1.CrimenameAdd();
ct1.testGet();
ct1.testIterator();
}
}
//********************
package storecrime;
import java.util.HashSet;
import java.util.Set;
public class Crimer {
String name;
String ID;
public Set Crimename;
public Crimer() {
this.name=name;
this.ID=ID;
this.Crimename=new HashSet();
}
}
//********************
package storecrime;
public class crimename {
String name;
String ID;
int rank;
public crimename(String name,String ID,int rank){
this.ID=ID;
this.name=name;
this.rank=rank;
}
}
相关分类