package com.test.library.newlib; import java.util.HashMap; import java.util.Map; import java.util.Set; //学生类 public class Students { private String sid;// 编号 private String name;// 姓名 private Map<Books, Integer> lendBooks = new HashMap<Books, Integer>(); // 构造 Students(String sid, String name) { this.sid = sid; this.name = name; } // get set方法 public String getSid() { return sid; } public void setSid(String sid) { this.sid = sid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Map<Books, Integer> getLendBooks() { return lendBooks; } public void setLendBooks(Map<Books, Integer> lendBooks) { this.lendBooks = lendBooks; } // int num:要借的数量 Books b:要借那本书 public void lendBooks(Books b, int num) { Set<Books> keys = this.getLendBooks().keySet(); for (Books temp : keys) { // 说明您曾经借过这本书 if (temp.getBid().equals(b.getBid())) { this.getLendBooks().put(temp, this.getLendBooks().get(temp) + num); return; } } // 说明你没有借过这本书 this.lendBooks.put(b, num); } // 展示所有借的图书 public void showAllLendBooks() { Set<Books> set = this.getLendBooks().keySet(); for (Books b : set) { System.out.println("图书编号:" + b.getBid() + " |书名:" + b.getName() + " 借书数量:" + this.getLendBooks().get(b)); } } // 查询――从借的书本里根据图书id查询 public Books getBooksByBid(String bid) { Set<Books> set = this.getLendBooks().keySet(); for (Books b : set) { if (b.getBid().equals(bid)) { return b; } } return null; } public int getBooksNumByBook(Books b) { Set<Books> set = this.getLendBooks().keySet(); for (Books temp : set) { if (temp.getBid().equals(b.getBid())) { return this.getLendBooks().get(temp); } } return -1; } public void returnBooks(Books b, int num) { this.getLendBooks().put(b, this.getLendBooks().get(b) - num); } public void returnBooks(Books b) { this.getLendBooks().remove(b); } }

啦啦啦rain LV1
2024年12月11日
xiaoyu111ewsd LV4
2024年1月7日
叼哉0909 LV1
2023年12月18日
upup996 LV6
2023年9月21日
poipoiiop LV8
2023年1月8日
52java LV1
2022年12月22日
15342201772 LV9
2022年12月4日
18871201024 LV4
2022年12月4日
GYYYYG LV1
2022年11月20日
rongyu LV1
2022年10月16日