日期:2014-05-20  浏览次数:20835 次

一道基础的数组应用问题
1.写出一个用户实体类UserEntity:
Java code
public class UserEntity 
{
    private String userId;
    private String userName;
    private String userPwd;
    private String realName;
    private int age;
    private String cellPhone;
    private String email;
    
    public String getUserId() 
    {
        return userId;
    }
    public void setUserId(String userId) 
    {
        this.userId = userId;
    }
    public String getUserName() 
    {
        return userName;
    }
    public void setUserName(String userName)
    {
        this.userName = userName;
    }
    public String getUserPwd() {
        return userPwd;
    }
    public void setUserPwd(String userPwd) 
    {
        this.userPwd = userPwd;
    }
    public String getRealName() 
    {
        return realName;
    }
    public void setRealName(String realName)
    {
        this.realName = realName;
    }
    public int getAge() 
    {
        return age;
    }
    public void setAge(int age)
    {
        this.age = age;
    }
    public String getCellPhone()
    {
        return cellPhone;
    }
    public void setCellPhone(String cellPhone) 
    {
        this.cellPhone = cellPhone;
    }
    public String getEmail() 
    {
        return email;
    }
    public void setEmail(String email) 
    {
        this.email = email;
    }
}


这部分没问题,关键是下面的:
写出一个数据仓库模拟类,要求属性包括用户实体数组,构造方法要初始化用户实体数组,至少5个用户信息。

我完全绕不过弯啊!求指点

------解决方案--------------------
Java code

package net.csdn.test;

public class UserFactory {

    private UserEntity[] entryArr;

    public UserFactory() {

        // 1st user
        UserEntity ue1 = new UserEntity();
        ue1.setAge(26);
        ue1.setCellPhone("88888888");
        ue1.setEmail("xxx@xxx.com");
        ue1.setRealName("RealName");
        ue1.setUserId("8888");
        ue1.setUserName("UserName");
        ue1.setUserPwd("UserPwd");

        // 2nd user
        UserEntity ue2 = new UserEntity();
        ue2.setAge(26);
        ue2.setCellPhone("88888888");
        ue2.setEmail("xxx@xxx.com");
        ue2.setRealName("RealName");
        ue2.setUserId("8888");
        ue2.setUserName("UserName");
        ue2.setUserPwd("UserPwd");

        // 3rd user
        UserEntity ue3 = new UserEntity();
        ue3.setAge(26);
        ue3.setCellPhone("88888888");
        ue3.setEmail("xxx@xxx.com");
        ue3.setRealName("RealName");
        ue3.setUserId("8888");
        ue3.setUserName("UserName");
        ue3.setUserPwd("UserPwd");

        // 4th user
        UserEntity ue4 = new UserEntity();
        ue4.setAge(26);
        ue4.setCellPhone("88888888");
        ue4.setEmail("xxx@xxx.com");
        ue4.setRealName("RealName");
        ue4.setUserId("8888");
        ue4.setUserName("UserName");
        ue4.setUserPwd("UserPwd");

        // 5th user
        UserEntity ue5 = new UserEntity();
        ue5.setAge(26);
        ue5.setCellPhone("88888888");
        ue5.setEmail("xxx@xxx.com");
        ue5.setRealName("RealName");
        ue5.setUserId("8888");
        ue5.setUserName("UserName");
        ue5.setUserPwd("UserPwd");

        entryArr = new UserEntity[] { ue1, ue2, ue3, ue4, ue5 };
    }
    
    public static void main(String[] args) {
        
        UserFactory uf = new UserFactory();
        System.out.println(uf.entryArr[0].getEmail());
    }
}

------解决方案--------------------
class UserEntity{
 private int[] ids;
 private String[] names;
 private String[] passwords;