增加用户绑定所借的书的功能
首先将用户借的书作为用户的一个属性进行新增
private String name;
private String password;
private Books books;
这样方便以后的赋值
将注册的每一个账号进行对象的新建,并对以下各个方法进行传参
public static void UsersLogin(ArrayList<Users> UsersDatas)
{
Users user = new Users();
while (true) {
int flag=1;
System.out.println("请输入用户的用户名");
Scanner scanner = new Scanner(System.in);
String Usersname = scanner.nextLine();
System.out.println("请输入用户的密码");
String password = scanner.nextLine();
for (int i = 0; i < UsersDatas.size(); i++) {
if (Usersname.equals(UsersDatas.get(i).getName()) && password.equals(UsersDatas.get(i).getPassword())) {
System.out.println("恭喜您!登录成功");
flag=0;
user=UsersDatas.get(i);
UserChoice(user);
break;
}
}
if (flag==1) {
System.out.println("不好意思账号或密码错误,请在输入一次");
}
}
}
将对象与账号密码进行绑定
public static void BorrowBook(ArrayList<Books> libraries,ArrayList<Books> Usersbooks, Users user )
{
System.out.println("请输入你要所要借书的id");
Scanner scanner = new Scanner(System.in);
String Bookid = scanner.nextLine();
for (int i = 0; i < libraries.size() ; i++) {
if (libraries.get(i).getId().equals(Bookid)) {
Usersbooks.add(libraries.get(i));
user.setBooks(libraries.get(i));
libraries.remove(i);
}
}
System.out.println("恭喜你,借书完毕,即将返回主页面");
UserChoice(user);
}
public static void Returnbook(ArrayList<Books> libraries,ArrayList<Books> Usersbooks, Users user )
{
System.out.println("请输入你要所要还书的id");
Scanner scanner = new Scanner(System.in);
String id = scanner.nextLine();
for (int i = 0; i < Usersbooks.size() ; i++) {
if (Usersbooks.get(i).getId().equals(id)) {
libraries.add(Usersbooks.get(i));
user.setBooks(null);
Usersbooks.remove(i);
}
}
System.out.println("恭喜你,还书完毕,即将返回主页面");
UserChoice(user);
}
借书还书绑定为对对象属性得操作
让管理员知道哪一个用户借了哪一本书
最后增加管理员查看用户数据的功能
public static void BossSeeAllUsersdate(ArrayList<Users> UsersDatas)
{
for (int i = 0; i< UsersDatas.size() ; i++) {
System.out.println(UsersDatas.get(i).getName());
if(UsersDatas.get(i).getBooks()!=null)
{
System.out.println("该用户借了"+UsersDatas.get(i).getBooks().getName());
}
}
BossChoice();
标签:功能,get,System,用户,UsersDatas,user,println,所借,out
From: https://www.cnblogs.com/lanyangyangxuejava/p/18681100