标题:ArrayList的问题!!急
只看楼主
kintarohe
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-7-8
 问题点数:0 回复次数:0 
ArrayList的问题!!急
*
* TestStaffs.java
* /

import java.util.ArrayList;

public class TestStaffs {

  public static void main(String[] args) {

    Build_Display_Persons bs = new Build_Display_Persons();

    // set up staffs
    ArrayList staffs = bs.build_persons();
    bs.display_person(staffs);

    // display staffs
    new Displaypersons (staffs);
  }

}

/*
* Person.java
* /

public class Person {
private String firstname;
private String lastname;
private int age;

public Person()
{ }

public String getFirstname() {
return firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}

/*
* Build_Display_Persons.java
* /

import java.util.ArrayList;

public class Build_Display_Persons {
  String [] fnames = {"Smon", "Weiming", "Yunzhe"};
  String [] lnames = {"Sheng", "He", "He"};
  int [] ages = {20, 59, 24};

  public ArrayList build_persons ()
  {
    ArrayList staffs = new ArrayList();
    int n = fnames.length;
    for (int i=0; i < n; i++)
    {
      Person p = new Person ();
      p.setFirstname(fnames[i]);
      p.setLastname(lnames[i]);
      p.setAge(ages[i]);
      staffs.add(p);
    }
    return staffs;
  }

  public void display_person (ArrayList alist)
  {
    for (int i=0; i < alist.size(); i++){
      Person p = (Person) alist.get(i);
      System.out.print(p.getFirstname()+"\t");
      System.out.print(p.getLastname()+"\t");
      System.out.println(p.getAge());
    }
  }
}
如何把?
a. ask user input firstname
b. ask user input lastname
c. ask user input age      加入TestStaffs.java

我如果我想建立个Search.java
只要有搜寻(firstname lastname age)功能 用arraylist方法!!

我在Core Java书上找不到怎么解决这2个问题方法!请高手帮我
搜索更多相关主题的帖子: ArrayList 
2005-07-08 17:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-22477-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.304064 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved