Java高级程序设计_JAVA高级程序设计求解

展开全部

时间有限我先把题一帮你解了,晚上在帮你解题二。题一代码如下,望采纳!

共三个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);

}

}

2962040ee45b80bff50a266e8359c02f.png

08e8d0016f3f99f9ed44e97fb8d42901.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值