日期:2014-05-20 浏览次数:20741 次
public class DbStore { private UserEntity[] entryArr;//声明一个数组变量 public DbStore() //初始化用户实体数组 { UserEntity ue1 = new UserEntity(); ue1.setAge(21); ue1.setCellPhone("888888881"); ue1.setEmail("damo1@qq.com"); ue1.setRealName("大漠1"); ue1.setUserId("001"); ue1.setUserName("damo1"); ue1.setUserPwd("1"); UserEntity ue5 = new UserEntity(); ue5.setAge(25); ue5.setCellPhone("888888885"); ue5.setEmail("damo5@qq.com"); ue5.setRealName("大漠5"); ue5.setUserId("005"); ue5.setUserName("damo5"); ue5.setUserPwd("5"); setEntryArr(new UserEntity[] { ue1, ue2, ue3, ue4, ue5 }); } public static void main(String[] args) { DbStore uf = new DbStore(); for(int i=0;i<uf.getEntryArr().length;i++) { System.out.println("用户编号:"+uf.getEntryArr()[i].getUserId()); System.out.println("登陆名称:"+uf.getEntryArr()[i].getUserName()); System.out.println("登陆密码:"+uf.getEntryArr()[i].getUserPwd()); System.out.println("真实姓名:"+uf.getEntryArr()[i].getRealName()); System.out.println("年龄:"+uf.getEntryArr()[i].getAge()); System.out.println("手机号码:"+uf.getEntryArr()[i].getCellPhone()); System.out.println("电子邮箱:"+uf.getEntryArr()[i].getEmail()); System.out.println("\r\n"); } } public void setEntryArr(UserEntity[] entryArr) { this.entryArr = entryArr; } public UserEntity[] getEntryArr() { return entryArr; } }
package User; import java.util.Scanner; public class UserManager { public static void main(String[] args) { DbStore abc = new DbStore(); Scanner input = new Scanner(System.in); System.out.println("请输入用户名:"); String name = input.next(); System.out.println("请输入密码:"); String password = input.next(); if((abc.getEntryArr()[i].userName!= name)||(abc.getEntryArr()[i].userPwd != password)) { System.out.println("用户不存在或密码错误!"); } else { System.out.println("该用户的真实姓名为"+abc.getEntryArr()[i].realName); } } }