用集合封装用户名,密码,地址,性别。java编写一个方法,参数为改集合,实现展示所有用户信息
答案:1 悬赏:60 手机版
解决时间 2021-03-18 17:29
- 提问者网友:人生佛魔见
- 2021-03-17 23:26
用集合封装用户名,密码,地址,性别。java编写一个方法,参数为改集合,实现展示所有用户信息
最佳答案
- 五星知识达人网友:愁杀梦里人
- 2021-03-18 00:57
public class User {
private String username;
private String password;
private String address;
private String sex;
public User(){}
public User(String username, String password, String address, String sex) {
super();
this.username = username;
this.password = password;
this.address = address;
this.sex = sex;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String toString() {
return this.getUsername()+","+this.getPassword()+","+this.getAddress()+","+this.getSex();
}
public List showAllInfo(){
User u=new User("name","upass","hz","male");
List userlist=new ArrayList();
userlist.add(u);
return userlist;
}
public static void main(String[] args) {
User u=new User();
List list=u.showAllInfo();
for (int i=0;i
System.out.println(list.get(i));
}
}
}
private String username;
private String password;
private String address;
private String sex;
public User(){}
public User(String username, String password, String address, String sex) {
super();
this.username = username;
this.password = password;
this.address = address;
this.sex = sex;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String toString() {
return this.getUsername()+","+this.getPassword()+","+this.getAddress()+","+this.getSex();
}
public List
User u=new User("name","upass","hz","male");
List
userlist.add(u);
return userlist;
}
public static void main(String[] args) {
User u=new User();
List
for (int i=0;i
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯