public class Pint {
/**
* 姓名
*/
public String name;
/**
* 年龄
*/
public String age;
public Pint(){
}
public Pint(String a,String s){
setName(a);
setAge(s);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
public class Kintz {
Hentr H=new Hentr();
Random random=new Random();
Scanner sc=new Scanner(System.in);
/**
* 创建姓名
*/
public void Hrn(){
System.out.println("请输入姓名");
String we=sc.next();
System.out.println("请输入年龄");
String we1=sc.next();
Pint a=new Pint(we, we1);
H.Ger(a);
}
/**
* 随机抽取姓名
*/
public void KIng(){
int as=random.nextInt(H.a.length);
System.out.println(H.a[as].name);
}
/**
* 排序输出
*/
public void compare() {
// TODO 自动生成的方法存根
Vector<String> v = new Vector<String>();
for(int i = 0 ; i < H.a.length;i++){
v.addElement(H.a[i].name);
}
Comparator cmp = Collator.getInstance(Locale.CHINA); //获得所需语言环境的Collator
Collections.sort(v, cmp); //根据指定比较器产生的顺序对v进行排序
System.out.println(v);
}
}
public class Hentr {
Pint[] a=new Pint[0];
public void Ger(Pint a1){
Pint[] s=new Pint[a.length+1];
for(int i=0;i<a.length;i++){
s[i]=a[i];
}
s[s.length-1]=a1;
a=s;
}
}
public class UIKom {
static Kintz K=new Kintz();
public static void main(String[] args) {
// TODO 自动生成的方法存根
while(true){
System.out.println("输入姓名年龄请按1");
System.out.println("随机请按2");
System.out.println("查询请按3");
String s=K.sc.next();
switch(s){
case "1":
K.Hrn();
break;
case "2":
K.KIng();
break;
case "3":
K.compare();
break;
}
}
}
}