# 图书管理系统案例练习

图书管理系统案例练习

1.date数据包

package date;

import java.io.File;
import java.io.Serializable;

import entity.*;
/**
 * 
 * @Description 数据类
 * @Author Mr.chen
 * @Date 2020年10月16日下午2:22:55
 * 
 * 此类用来储存在内存中处理各个数据,在程序结束的时候写入配置文件
 * 
 * Book[]   用来储存书籍的各个信息
 * BookAccount[]  用来储存管理员账户		管理员账户账号默认admin
 * BookPersonBorrowReturn[]		用来储存个人账户的各种信息 包括借书时间 归还时间 借书名称
 * 
 * fileBook   用来永久保存书籍的各个信息
 * fileBookAccount		用来永久储存账户
 * fileBookPersonBorrowReturn	用来永久储存个人借阅归还的信息
 */
public class DateBook implements Serializable{
    
    
	
	/**
	 * @Description
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午4:23:14
	 */
	private static final long serialVersionUID = -406169565854901850L;
	public static Book[] book = new Book[100];
	public static BookPersonAccount[] baa = new BookPersonAccount[100];
	public static BookBorrowList[] bpbr = new BookBorrowList[100];
	
	
	public static File fileBook = new File("fileBook.ini"); 
	public static File BookPersonAccount = new File("BookPersonAccount.ini"); 
	public static File BookBorrowList = new File("BookBorrowList.ini"); 

//用于数据的初始化这里加载了一遍,就注释掉了
//	static {
    
    
//		Book book1 = new Book("我的世界",100,10);
//		Book book2 = new Book("三国演义",50,10);
//		Book book3 = new Book("红楼梦",100,40);
//		book[0] = book1;
//		book[1] = book2;
//		book[2] = book3;
//		
//		BookPersonAccount bpa = new BookPersonAccount("xiexun","123456","谢逊");
//		BookPersonAccount bpa1 = new BookPersonAccount("admin","111111","管理员");
//		baa[0] = bpa;
//		baa[1] = bpa1;
//		
//	}
}

2.entity实体类包

package entity;

import java.io.Serializable;

/**
 * 
 * @Description DVD实体类
 * @Author Mr.chen
 * @Date 2020年10月15日上午11:41:40
 * 
 * DVD实体类,这个类定义了DVD的名字,库存数量,借阅数量,借阅价格
 */
public class Book implements Serializable {
    
    
	/**
	 * 序列化异常,将本地序列号改至与远程序列号相同
	 */
	private static final long serialVersionUID = 4617879176992662261L;

	private String dvdName;// 名字
	private int dvdNums;// 库存数量
	private int dvdBNums;// 借阅数量
	private double dvdPrice;// 借阅价格

	public Book() {
    
    
		super();
	}

	public Book(String dvdName, int dvdNums, double dvdPrice) {
    
    
		super();
		this.dvdName = dvdName;
		this.dvdNums = dvdNums;
		this.dvdBNums = 0;
		this.dvdPrice = dvdPrice;
	}

	public String getDvdName() {
    
    
		return dvdName;
	}

	public void setDvdName(String dvdName) {
    
    
		this.dvdName = dvdName;
	}

	public int getDvdNums() {
    
    
		return dvdNums;
	}

	public void setDvdNums(int dvdNums) {
    
    
		this.dvdNums = dvdNums;
	}

	public int getDvdBNums() {
    
    
		return dvdBNums;
	}

	public void setDvdBNums(int dvdBNums) {
    
    
		this.dvdBNums = dvdBNums;
	}

	public double getDvdPrice() {
    
    
		return dvdPrice;
	}

	public void setDvdPrice(double dvdPrice) {
    
    
		this.dvdPrice = dvdPrice;
	}

}

package entity;

import java.io.Serializable;
import java.util.Date;

/**
 * 
 * @Description 借阅列表实体类
 * @Author Mr.chen
 * @Date 2020年10月16日下午3:21:21
 * 
 *       这个类用来记录书籍记录用户的借阅信息
 */
public class BookBorrowList implements Serializable{
    
    

	/**
	 * @Description
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午4:23:09
	 */
	private static final long serialVersionUID = -3653504482410226115L;
	private String personAccount;// 借阅人账户
	private String bookName;// 借阅书籍名称
	private Date borrowDate;// 借阅日期
	private Date returnDate;// 归还日期

	public BookBorrowList() {
    
    
		super();
	}

	public BookBorrowList(String personAccount, String bookName, Date borrowDate, Date returnDate) {
    
    
		super();
		this.personAccount = personAccount;
		this.bookName = bookName;
		this.borrowDate = borrowDate;
		this.returnDate = returnDate;
	}

	public String getPersonAccount() {
    
    
		return personAccount;
	}

	public void setPersonAccount(String personAccount) {
    
    
		this.personAccount = personAccount;
	}

	public String getBookName() {
    
    
		return bookName;
	}

	public void setBookName(String bookName) {
    
    
		this.bookName = bookName;
	}

	public Date getBorrowDate() {
    
    
		return borrowDate;
	}

	public void setBorrowDate(Date borrowDate) {
    
    
		this.borrowDate = borrowDate;
	}

	public Date getReturnDate() {
    
    
		return returnDate;
	}

	public void setReturnDate(Date returnDate) {
    
    
		this.returnDate = returnDate;
	}

}

package entity;

import java.io.Serializable;

/**
 * 
 * @Description DVD借阅个人实体类
 * @Author Mr.chen
 * @Date 2020年10月15日下午3:41:08
 * 
 *       这个类定义借阅人的个人账号,个人密码以及借书情况
 * 
 */
public class BookPersonAccount implements Serializable{
    
    

	/**
	 * @Description
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午4:23:04
	 */
	private static final long serialVersionUID = -3442924235778915049L;
	private String personAccount;// 个人账户
	private String pwg;// 个人密码
	private String name;// 昵称

	public String getName() {
    
    
		return name;
	}

	public BookPersonAccount(String personAccount, String pwg, String name) {
    
    
		super();
		this.personAccount = personAccount;
		this.pwg = pwg;
		this.name = name;
	}

	public void setName(String name) {
    
    
		this.name = name;
	}

	public BookPersonAccount() {
    
    
		super();
	}

	public String getPersonAccount() {
    
    
		return personAccount;
	}

	public void setPersonAccount(String personAccount) {
    
    
		this.personAccount = personAccount;
	}

	public String getPwg() {
    
    
		return pwg;
	}

	public void setPwg(String pwg) {
    
    
		this.pwg = pwg;
	}

}

3.service逻辑包

package service;

import java.util.Date;

import date.DateBook;
import entity.Book;
import entity.BookBorrowList;
import entity.BookPersonAccount;
import util.DateUtil;

public class BookService {
    
    
	
	/**
	 * 
	 * @Description 查看图书列表
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午1:55:20
	 * return:
	 */
	public void showAllBookList() {
    
    
		System.out.println("名字\t\t库存数量\t借阅数量\t借阅价格");
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] != null) {
    
    
				String str = String.format("%s\t\t%s\t%s\t%s\t", DateBook.book[i].getDvdName(),DateBook.book[i].getDvdNums(),DateBook.book[i].getDvdBNums(),DateBook.book[i].getDvdPrice());
				System.out.println(str);
			}
		}
	}
	
	/**
	 * 
	 * @Description 判断输入书名是否存在
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午2:46:55
	 * return:
	 */
	public Book bookNameExist(String name) {
    
    
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] != null) {
    
    
				if(DateBook.book[i].getDvdName().equals(name)) {
    
    
					return DateBook.book[i];
				}
			}
		}
		return null;
	}
	
	
	/**
	 * 
	 * @Description 个人借阅书籍功能
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午1:58:43
	 * return:
	 */
	public void borrowBook(Book book,BookPersonAccount account) {
    
    
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] != null) {
    
    
				if(DateBook.book[i].getDvdName().equals(book.getDvdName())) {
    
    
					DateBook.book[i].setDvdNums(DateBook.book[i].getDvdNums() - 1);
					DateBook.book[i].setDvdBNums(DateBook.book[i].getDvdBNums() + 1);
					borrowBookList(DateBook.book[i],account);
					break;
				}
			}
		}
	}
	
	private void borrowBookList(Book book,BookPersonAccount account) {
    
    
		for(int i = 0;i < DateBook.bpbr.length;i++) {
    
    
			if(DateBook.bpbr[i] == null) {
    
    
				BookBorrowList db = new BookBorrowList();
				db.setPersonAccount(account.getPersonAccount());
				db.setBookName(book.getDvdName());
				db.setBorrowDate(new Date());
				DateBook.bpbr[i] = db;
				break;
			}
		}
	}
	
	/**
	 * 
	 * @Description 查看我的借阅记录
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午1:57:07
	 * return:
	 */
	public void showMyBookBorrowList(BookPersonAccount account) {
    
    
		System.out.println("借阅人账户\t借阅书籍名称\t借阅日期\t\t归还日期");
		for(int i = 0 ;i < DateBook.bpbr.length;i++) {
    
    
			if(DateBook.bpbr[i] != null) {
    
    
				if(DateBook.bpbr[i].getPersonAccount().equals(account.getPersonAccount())) {
    
    
					String str = String.format("%s\t%s\t\t%s\t\t%s\t", DateBook.bpbr[i].getPersonAccount(),DateBook.bpbr[i].getBookName(),DateUtil.showDate(DateBook.bpbr[i].getBorrowDate()),DateUtil.showDate(DateBook.bpbr[i].getReturnDate()));
					System.out.println(str);
				}
			}
		}
		
	}
	
	/**
	 * 
	 * @Description 查看所有借阅记录 管理员权利
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午2:53:43
	 * return:
	 */
	public void showAllBookBorrowList() {
    
    
		System.out.println("借阅人账户\t借阅书籍名称\t借阅日期\t归还日期");
		for(int i = 0 ;i < DateBook.bpbr.length;i++) {
    
    
			if(DateBook.bpbr[i] != null) {
    
    
				String str = String.format("%s\t%s\t\t%s\t\t%s\t", DateBook.bpbr[i].getPersonAccount(),DateBook.bpbr[i].getBookName(),DateUtil.showDate(DateBook.bpbr[i].getBorrowDate()),DateUtil.showDate(DateBook.bpbr[i].getReturnDate()));
				System.out.println(str);
			}
		}
	}
	
	/**
	 * 
	 * @Description 个人账户归还书籍
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:05:27
	 * return:
	 */
	public void returnBook(Book book, BookPersonAccount account) {
    
    
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] != null) {
    
    
				if(DateBook.book[i].getDvdName().equals(book.getDvdName())) {
    
    
					DateBook.book[i].setDvdNums(DateBook.book[i].getDvdNums() + 1);
					DateBook.book[i].setDvdBNums(DateBook.book[i].getDvdBNums() - 1);
					returnBookList(DateBook.book[i],account);
					break;
				}
			}
		}
	}
	
	private void returnBookList(Book book,BookPersonAccount account) {
    
    
		for(int i = 0;i < DateBook.bpbr.length;i++) {
    
    
			if(DateBook.bpbr[i] != null) {
    
    
				if(DateBook.bpbr[i].getPersonAccount().equals(account.getPersonAccount())) {
    
    
					Date returnDate = new Date();
					DateBook.bpbr[i].setReturnDate(returnDate);
					Date borrowDate = DateBook.bpbr[i].getBorrowDate();
					long time = returnDate.getTime() - borrowDate.getTime();
					double price = (time/(1000*3600*24))*book.getDvdPrice();
					System.out.println("还书成功,应付:" + price);
					break;
				}
			}
		}
	}
	
	/**
	 * 
	 * @Description 管理员添加书籍
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:43:39
	 * return:
	 */
	public void addBook(String name ,int bookNum,double bookPrice) {
    
    
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] != null) {
    
    
				if(DateBook.book[i].getDvdName().equals(name)) {
    
    
					DateBook.book[i].setDvdNums(DateBook.book[i].getDvdNums() + bookNum);
					DateBook.book[i].setDvdPrice(bookPrice);
					return;
				}
			}
		}
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] == null) {
    
    
				Book book = new Book(name,bookNum,bookPrice);
				DateBook.book[i] = book;
				break;
			}
		}
	}
	
	/**
	 * 
	 * @Description 管理员删除书籍
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:43:49
	 * return:
	 */
	public void deleteBook(String name) {
    
    
		for(int i = 0;i < DateBook.book.length;i++) {
    
    
			if(DateBook.book[i] != null) {
    
    
				if(DateBook.book[i].getDvdName().equals(name)) {
    
    
					DateBook.book[i] = null;
					break;
				}
			}
		}
	}
	
	
	
	
	
	
}

package service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

import entity.Book;
import entity.BookBorrowList;
import entity.BookPersonAccount;

/**
 * 
 * @Description 这个类保存着读取文件中数组的方法
 * @Author Mr.chen
 * @Date 2020年10月17日下午4:02:54
 */
public class DateReadToFile {
    
    
	
	/**
	 * 
	 * @throws ClassNotFoundException 
	 * @Description 读取文档中的书籍信息
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午4:03:57
	 * return:
	 */
	public static Book[] readBook(File fileBook) throws FileNotFoundException, IOException, ClassNotFoundException {
    
    
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileBook));
		Book[] book = (Book[])ois.readObject();
		ois.close();
		return book;
	}
	
	/**
	 * 
	 * @throws ClassNotFoundException 
	 * @Description 读取文档中的个人账号
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午4:04:35
	 * return:
	 */
	public static BookPersonAccount[] readBookAdminAccount(File fileBookAdminAccount) throws FileNotFoundException, IOException, ClassNotFoundException {
    
    
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileBookAdminAccount));
		BookPersonAccount[] bookAdminAccount = (BookPersonAccount[])ois.readObject();
		ois.close();
		return bookAdminAccount;
	}
	
	/**
	 *  
	 * @throws ClassNotFoundException 
	 * @Description 读取文档中书籍借阅信息
	 * @Author Mr.chen 
	 * @Date 2020年10月17日下午4:04:45
	 * return:
	 */
	public static BookBorrowList[] readBookPersonBorrowReturn(File fileBookPersonBorrowReturn) throws FileNotFoundException, IOException, ClassNotFoundException {
    
    
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileBookPersonBorrowReturn));
		BookBorrowList[] bookPersonBorrowReturn = (BookBorrowList[])ois.readObject();
		ois.close();
		return bookPersonBorrowReturn;
	}
	
	
}

package service;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import entity.Book;
import entity.BookBorrowList;
import entity.BookPersonAccount;



/**
 * 
 * @Description 将数组中的数据写入配置文件
 * @Author Mr.chen
 * @Date 2020年10月16日下午2:28:58
 */
public class DateSaveToFile {
    
    
	
	/**
	 * 
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @Description 将书籍的信息写入配置文件
	 * @Author Mr.chen
	 * @Date 2020年10月16日下午2:31:52
	 * return:
	 */
	public static void save(Book[] book,File fileBook) throws FileNotFoundException, IOException {
    
    
		ObjectOutputStream ois = new ObjectOutputStream(new FileOutputStream(fileBook));
		ois.writeObject(book);
		ois.close();
	}
	
	/**
	 * 
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @Description 将账户信息写入文件中
	 * @Author Mr.chen
	 * @Date 2020年10月16日下午2:32:16
	 * return:
	 */
	public static void save(BookPersonAccount[] baa,File fileBookAdminAccount) throws FileNotFoundException, IOException {
    
    
		ObjectOutputStream ois = new ObjectOutputStream(new FileOutputStream(fileBookAdminAccount));
		ois.writeObject(baa);
		ois.close();
	}
	
	/**
	 * 
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @Description 将借阅和归还的信息写入文件中
	 * @Author Mr.chen
	 * @Date 2020年10月16日下午2:32:41
	 * return:
	 */
	public static void save(BookBorrowList[] bpbr,File fileBookPersonBorrowReturn) throws FileNotFoundException, IOException {
    
    
		ObjectOutputStream ois = new ObjectOutputStream(new FileOutputStream(fileBookPersonBorrowReturn));
		ois.writeObject(bpbr);
		ois.close();
	}
	
	
	
}

package service;

import date.DateBook;
import entity.BookPersonAccount;

/**
 * 
 * @Description 个人账号逻辑管理
 * @Author Mr.chen
 * @Date 2020年10月15日下午4:20:34
 * 
 * 此类所定义的功能有  个人账号登录账号匹配检索  个人账号注册  个人账号密码修改
 * 
 */
public class PersonAccountService {
    
    
	
	
	/**
	 * 
	 * @Description 判断账户是否存在 
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午4:36:17
	 * return: 如果存在返回对应的对象   如果不存在返回null
	 */
	public BookPersonAccount personAccountExist(String personAccount) {
    
    
		for(int i = 0;i < DateBook.baa.length;i++) {
    
    
			if(DateBook.baa[i] != null) {
    
    
				if(DateBook.baa[i].getPersonAccount().equals(personAccount)) {
    
    
					return DateBook.baa[i];
				}
			}
		}
		return null;
	}
	
	/**
	 * 
	 * @Description 判断账户的输入的密码和文件中储存的密是否相同
	 * @Author Mr.chen
	 * @Date 2020年10月16日下午2:52:25
	 * return:
	 */
	public boolean personPwgTrueOrFalse(String personInputPwg,String personSavePwg) {
    
    
		return personInputPwg.equals(personSavePwg);
	}
	
	/**
	 * 
	 * @Description 个人用户注册
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午4:41:33
	 * return:
	 */
	public void personLogin(String personAccount, String personPwg1,String personName) {
    
    
		for(int i = 0;i < DateBook.baa.length;i++) {
    
    
			if(DateBook.baa[i] == null) {
    
    
				BookPersonAccount bpa = new BookPersonAccount(personAccount,personPwg1,personName);
				DateBook.baa[i] = bpa;
				break;
			}
		}
	}
	
	/**
	 * 
	 * @Description 密码修改逻辑 
	 * @Author Mr.chen
	 * @Date 2020年10月16日上午8:49:28
	 * 
	 * 将密码写入对应的账号
	 */
	public void personChangePwg(BookPersonAccount pae) {
    
    
		for(int i = 0;i < DateBook.baa.length;i++) {
    
    
			if(DateBook.baa[i].getPersonAccount().equals(pae.getPersonAccount())) {
    
    
				DateBook.baa[i] = pae;
				break;
			}
		}
	}
	
	
}

4.start启动包

package start;

import ui.BookMainUI;
/**
 * 
 * @Description 启动类
 * @Author Mr.chen
 * @Date 2020年10月16日下午3:41:07
 */
public class StartApp {
    
    
	public static void main(String[] args) {
    
    
		BookMainUI bmui = new BookMainUI();
		bmui.dvdMainUI();
	}
}

5.ui界面包

package ui;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import date.DateBook;
import service.DateReadToFile;
import service.DateSaveToFile;

/**
 * 
 * @Description 项目主界面
 * @Author Mr.chen
 * @Date 2020年10月15日下午3:58:59
 * 
 *       这个类设计项目的主界面 主要功能有普通用户登录,普通用户注册,管理员登录,普通用户修改密码
 * 
 */
public class BookMainUI {
    
    

	Scanner input = new Scanner(System.in);
	PersonAccountUI pau = new PersonAccountUI();

	/**
	 * 
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @Description 图书管理系统主界面
	 * @Author Mr.chen
	 * @Date 2020年10月17日上午10:59:28 return:
	 */
	public void dvdMainUI() {
    
    

		try {
    
    
			DateBook.book = DateReadToFile.readBook(DateBook.fileBook);
			DateBook.baa = DateReadToFile.readBookAdminAccount(DateBook.BookPersonAccount);
			DateBook.bpbr = DateReadToFile.readBookPersonBorrowReturn(DateBook.BookBorrowList);
		} catch (FileNotFoundException e1) {
    
    
			System.out.println("文件找不到!");
		} catch (ClassNotFoundException e1) {
    
    
			System.out.println("类找不到!");
		} catch (IOException e1) {
    
    
			System.out.println("读取失败!");
		}

		while (true) {
    
    
			System.out.println("======================================================");
			System.out.println("-------------------欢迎使用DVD租赁系统--------------------");
			System.out.println("---------------尊敬的用户请问你要进行什么操作?----------------");
			System.out.println("-----------------------------------------------------");
			System.out.println("--------------------1.用户登录--------------------------");
			System.out.println("--------------------2.用户注册--------------------------");
			System.out.println("--------------------3.用户修改密码-----------------------");
			System.out.println("--------------------4.退出-----------------------------");
			System.out.println("======================================================");

			int choice = 0;
			try {
    
    
				choice = input.nextInt();
			} catch (Exception e) {
    
    
				System.out.println("您输入的指令类型不正确!请重新输入:");
			}

			if (choice == 1) {
    
    
				pau.personOnloadUI();
			} else if (choice == 2) {
    
    
				pau.personLoginUI();
			} else if (choice == 3) {
    
    
				pau.personExistChangePwg();
			} else if (choice == 4) {
    
    
				break;
			} else {
    
    
				System.out.println("您输入的指令不匹配,请输入正确的数字!");
			}

		}

		try {
    
    
			DateSaveToFile.save(DateBook.book, DateBook.fileBook);
			DateSaveToFile.save(DateBook.baa, DateBook.BookPersonAccount);
			DateSaveToFile.save(DateBook.bpbr, DateBook.BookBorrowList);
		} catch (FileNotFoundException e) {
    
    
			System.out.println("文件找不到!");
		} catch (IOException e) {
    
    
			System.out.println("写入失败!");
		}
	}

}

package ui;

import java.util.Scanner;

import entity.Book;
import entity.BookPersonAccount;
import service.BookService;
import service.PersonAccountService;

/**
 * 
 * @Description 个人用户登录界面
 * @Author Mr.chen
 * @Date 2020年10月15日下午4:13:47
 * 
 * 个人用户登录界面输入账号和密码  并在个人用户逻辑类判断账号密码是否正确
 *
 */
public class PersonAccountUI {
    
    
	
	private PersonAccountService pas = new PersonAccountService();
	private Scanner input = new Scanner(System.in);
	private BookService bs = new BookService();
	/**
	 * 
	 * @Description 个人账户登录界面
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午4:22:15
	 * 
	 */
	public void personOnloadUI(){
    
    
		
		System.out.println("======================================================");
		System.out.println("请输入你的账号:");
		String personAccount = input.next();
		System.out.println("请输入你的密码:");
		String personPwg = input.next();
		BookPersonAccount pae = pas.personAccountExist(personAccount);
		if(pae != null) {
    
    
			boolean pptof = pas.personPwgTrueOrFalse(personPwg, pae.getPwg());
			if(pptof) {
    
    
				System.out.println("登陆成功!");
				if(pae.getPersonAccount().equals("admin")) {
    
    
					adminUI(pae);
				}else {
    
    
					personBorrowUI(pae);
				}
			}else {
    
    
				System.out.println("您输入的密码不匹配,请重新输入!");
				personOnloadUI();
			}
		}else {
    
    
			System.out.println("您输入的账户不正确,请重新输入!");
			System.out.println("是否继续登录?输入1.是(输入任意数字返回上一层)");
			int choice = input.nextInt();
			if(choice == 1) {
    
    
				personOnloadUI();
			}
		}
		
	}
	
	/**
	 * 
	 * @Description 管理员界面
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:15:55
	 * 
	 * 管理员权限   查看列表   添加书籍  删除书籍   查看所有借阅记录   
	 */
	public void adminUI(BookPersonAccount pae) {
    
    
		while(true) {
    
    
			System.out.println("======================================================");
			System.out.println("1.查看列表2.添加书籍3.删除书籍4.查看所有借阅记录5.退出");
			int choice = input.nextInt();
			if(choice == 1) {
    
    
				bs.showAllBookList();
			}else if(choice == 2) {
    
    
				addBookUI();
			}else if(choice == 3) {
    
    
				deleteBookUI();
			}else if(choice == 4) {
    
    
				bs.showAllBookBorrowList();
			}else if(choice == 5) {
    
    
				break;
			}else {
    
    
				System.out.println("请输入正确的数字!");
			}
		}
	}
	
	/**
	 * 
	 * @Description 管理员添加界面
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:40:25
	 * return:
	 */
	public void addBookUI() {
    
    
		System.out.println("======================================================");
		System.out.println("请输入你要添加的书名:");
		String name = input.next();
		System.out.println("请输入添加书籍的数量:");
		int bookNum = input.nextInt();
		System.out.println("请输入添加书籍的价格:");
		double bookPrice = input.nextDouble();
		bs.addBook(name, bookNum,bookPrice);
	}
	
	/**
	 * 
	 * @Description 管理员删除界面
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:40:34
	 * return:
	 */
	public void deleteBookUI() {
    
    
		System.out.println("======================================================");
		System.out.println("请输入要删除书籍的名称:");
		String name = input.next();
		bs.deleteBook(name);
	}
	
	/**
	 * 
	 * @Description 个人账户注册管理
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午4:23:11
	 * 
	 */
	public void personLoginUI() {
    
    
		System.out.println("======================================================");
		System.out.println("请输入你的昵称:");
		String personName = input.next();
		System.out.println("请输入你的账号:");
		String personAccount = input.next();
		System.out.println("请输入你的密码:");
		String personPwg1 = input.next();
		System.out.println("请第二次输入你的密码:");
		String personPwg2 = input.next();
		BookPersonAccount pae = pas.personAccountExist(personAccount);
		if(pae == null) {
    
    
			if(personPwg1.equals(personPwg2)) {
    
    
				pas.personLogin(personAccount,personPwg1,personName);
				System.out.println("注册成功");
			}else {
    
    
				System.out.println("您输入的密码不相同请重新输入!");
				personLoginUI();
			}
		}else {
    
    
			System.out.println("您输入的账户已存在,请重新输入!");
			System.out.println("是否继续登录?输入1.是(输入任意数字返回上一层)");
			int choice = input.nextInt();
			if(choice == 1) {
    
    
				personOnloadUI();
			}
		}
		
	}
	
	/**
	 * 
	 * @Description	个人账户密码修改确认界面
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午4:23:55
	 * 
	 * 先输入原有的账户密码 判断是否
	 */
	public void personExistChangePwg() {
    
    
		System.out.println("======================================================");
		System.out.println("请输入你要修改密码的账户:");
		String personAccount = input.next();
		System.out.println("请输入原来的密码:");
		String personPwg = input.next();
		BookPersonAccount pae = pas.personAccountExist(personAccount);
		if(pae != null) {
    
    
			boolean pptof = pas.personPwgTrueOrFalse(personPwg, pae.getPwg());
			if(pptof) {
    
    
				personChangePwg(pae);
			}else {
    
    
				System.out.println("您输入的密码不匹配,请重新输入!");
				personExistChangePwg();
			}
		}else {
    
    
			System.out.println("您输入的账户不正确,请重新输入!");
			System.out.println("是否继续修改密码?输入1.是(输入其他任意数字返回上一层)");
			int choice = input.nextInt();
			if(choice == 1) {
    
    
				personOnloadUI();
			}
		}
		
	}
	
	/**
	 * 
	 * @param pae 
	 * @Description 个人账户密码修改界面
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午4:52:05
	 * return:
	 */
	public void personChangePwg(BookPersonAccount pae) {
    
    
		System.out.println("======================================================");
		System.out.println("请输入你的新密码");
		String newPwg1 = input.next();
		System.out.println("请再次输入你的新密码");
		String newPwg2 = input.next();
		if(newPwg1.equals(newPwg2)) {
    
    
			pae.setPwg(newPwg1);
			pas.personChangePwg(pae);
			System.out.println("密码修改成功");
		}else {
    
    
			System.out.println("前后输入的密码不一样!");
			personChangePwg(pae);
		}
		
	}
	
	/**
	 * 
	 * @Description 个人登录后界面 
	 * @Author Mr.chen
	 * @Date 2020年10月16日上午9:12:21
	 * 
	 * 
	 * 	功能:借阅  查看借阅记录 退出
	 * 
	 */
	public void personBorrowUI(BookPersonAccount account) {
    
    
		while(true) {
    
    
			System.out.println("======================================================");
			System.out.println("1.查看图书列表2.借阅书籍3.查看我的借阅记录4.归还书籍5.退出");
			int choice = input.nextInt();
			if(choice == 1) {
    
    
				bs.showAllBookList();
			}else if(choice == 2){
    
    
				bookBorrowUI(account);
			}else if(choice == 3){
    
    
				bs.showMyBookBorrowList(account);
			}else if(choice == 4){
    
    
				personReturnUI(account);
			}else if(choice == 5){
    
    
				break;
			}else {
    
    
				System.out.println("请输入正确的数字指令!");
			}
		}
	}
	
	/**
	 * 
	 * @Description 借阅书籍界面
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:03:45
	 * return:
	 */
	private void bookBorrowUI(BookPersonAccount account) {
    
    
		System.out.println("======================================================");
		System.out.println("请输入你要借阅书籍的名字:");
		String name = input.next();
		Book book = bs.bookNameExist(name);
		if(book != null) {
    
    
			bs.borrowBook(book,account);
			System.out.println("借阅成功!");
		}else {
    
    
			System.out.println("你输入的书名不存在,请重新选择!");
		}
		
	}
	
	/**
	 *  
	 * @Description 个人还书界面
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午3:03:05
	 * return:
	 */
	private void personReturnUI(BookPersonAccount account) {
    
    
		System.out.println("======================================================");
		System.out.println("请输入你要归还书籍的名字:");
		String name = input.next();
		Book book = bs.bookNameExist(name);
		if(book != null) {
    
    
			bs.returnBook(book,account);
			System.out.println("归还成功!");
		}else {
    
    
			System.out.println("你输入的书名不存在,请重新选择!");
		}
		
	}
}

6.util工具包

package util;
/**
 * 
 * @Description 枚举类,使得打印的日期按照固定的格式
 * @Author Mr.chen
 * @Date 2020年10月19日上午10:11:18
 */
public enum DateType {
    
    
	
	/**
	 * dd-MM-yyyy
	 * 
	 */
	FORMATS1,
	/**
	 * ddMMyyyy
	 * 
	 */
	FORMATS2,
	/**
	 * dd年MM月yyyy日
	 * 
	 */
	FORMATS3
}

package util;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil implements Serializable{
    
    
	
	private static final long serialVersionUID = 4217769403151410614L;
	private static Date date = new Date();//借出的日期
	private static final String FORMATS1 = "dd-MM-yyyy";
	private static final String FORMATS2 = "ddMMyyyy";
	private static final String FORMATS3 = "dd年MM月yyyy日";
	
	/**
	 * @Description 返回当前 String类型时间
	 * @Author Mr.chen
	 * @Date 2020年10月15日上午11:32:37
	 */
	public static String BorrowDate(DateType formate) {
    
    
		SimpleDateFormat sdf = null;
		switch (formate) {
    
    
			case FORMATS1: 
				sdf = new SimpleDateFormat(FORMATS1);
				break;
			case FORMATS2: 
				sdf = new SimpleDateFormat(FORMATS2);
				break;
			case FORMATS3: 
				sdf = new SimpleDateFormat(FORMATS3);
				break;
		}
		return sdf.format(date);
	}
	
	/**
	 * 
	 * @Description 将String类型日期转换为Date类型对象
	 * @Author Mr.chen
	 * @Date 2020年10月15日下午12:06:21
	 * return: Date Object
	 */
	public static Date strToDate(String date , DateType formate) throws ParseException {
    
    
		SimpleDateFormat sdf = null;
		switch (formate) {
    
    
			case FORMATS1: 
				sdf = new SimpleDateFormat(FORMATS1);
				break;
			case FORMATS2: 
				sdf = new SimpleDateFormat(FORMATS2);
				break;
			case FORMATS3: 
				sdf = new SimpleDateFormat(FORMATS3);
				break;
		}
		return sdf.parse(date);
	}
	
	/**
	 * 
	 * @Description 计算两个Date类型对象相差的时间     date1 - date2
	 * @Author Mr.chen
	 * @Date 2020年10月15日上午11:27:38
	 * date1  前一个date对象
	 * date2  后一个date对象
	 * 
	 * return: day int 
	 * 返回两个日期之间相差多少天
	 */
	public static int dateCale(Date date1, Date date2) {
    
    
		long time = date1.getTime() - date2.getTime();
		int day = (int)(time/(1000 * 3600 * 24));
		return day;
	}
	
	/**
	 * 
	 * @Description 打印出对应的Date的日期
	 * @Author Mr.chen
	 * @Date 2020年10月17日下午2:33:22
	 * return:
	 */
	public static String showDate(Date date) {
    
    
		if(date != null) {
    
    
			SimpleDateFormat sdf = new SimpleDateFormat(FORMATS1);
			String str = sdf.format(date);
			return str;
		}
		return "";
	}
}

猜你喜欢

转载自blog.csdn.net/OrangeNotFat/article/details/109155615