首页>代码>java控制台图书馆管理系统>/library/src/com/test/library/newlib/Students.java
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);
	}

}
最近下载更多
xiaoyu111ewsd  LV4 1月7日
叼哉0909  LV1 2023年12月18日
upup996  LV6 2023年9月21日
poipoiiop  LV8 2023年1月8日
52java  LV1 2022年12月22日
15342201772  LV7 2022年12月4日
18871201024  LV4 2022年12月4日
GYYYYG  LV1 2022年11月20日
rongyu  LV1 2022年10月16日
努力的小白程序员  LV3 2022年6月23日
最近浏览更多
朱俪的邮件及存储  LV8 3月26日
周青松197  LV2 3月12日
xiaoyu111ewsd  LV4 1月7日
3608478377 1月5日
暂无贡献等级
zsh040214 1月4日
暂无贡献等级
jiayongchao258  LV9 2023年12月28日
asddwh  LV12 2023年12月26日
ddzfgh  LV1 2023年12月25日
lijaiqi775  LV1 2023年12月25日
gecongkai  LV8 2023年12月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友