定义一个User类,包括:数据成员——用户名、密码;方法成员——身份验证、修改密码。用Java怎么编写,思路也行
2 回答
已采纳
最初__
TA贡献68条经验 获得超39个赞
public class User { private String username; private String password; public User(String username, String password) { this.username = username; this.password = password; } public boolean identify(String username, String password) { return (this.username.equals(username)) && (this.password.equals(password)); } public String modifyPassword(String oldPassword, String newPassword) { String tip; if (this.password.equals(oldPassword)) { this.password = newPassword; tip = "密码修改成功"; } else { tip = "密码修改失败"; } return tip; } public String getPassword() { return this.password; } public String getUsername() { return this.username; } }
添加回答
举报
0/150
提交
取消