展开全部
时间有限我先把题一帮你解了,晚上在帮你解题二。题一代码如下,望采纳!
共三个java文件测试截图也在32313133353236313431303231363533e4b893e5b19e31333363386138后面!
//定义User类
public class User {
private String username;
private String password;
//定义默认构造方法
public User() {
this.username = "admin";
this.password = "1234";
}
public static User checkUser(String username, String password) throws NoSuchUserException, PasswordDontMatchException {
User user = new User();
if (!user.username.equals(username)) {
throw new NoSuchUserException("用户名不匹配!");
}
if (!user.password.equals(password)) {
throw new PasswordDontMatchException("密码不匹配!");
}
return user;
}
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 class NoSuchUserException extends Exception {
public NoSuchUserException(String msg) {
super(msg);
}
}
public class PasswordDontMatchException extends Exception {
public PasswordDontMatchException(String msg) {
super(msg);
}
}