Package week6.bookmanagement;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.OutputStream;
Import Java.text.SimpleDateFormat;
Import java.util.ArrayList;
Import Java.util.Calendar;
Import Java.util.GregorianCalendar;
Import java.util.Properties;
/**
*
* @author Quanby
*
*/
public class Bookutil {
/**
* Book Help Class
*/
Public Bookutil () {
Super ();
TODO auto-generated Constructor stub
}
/**
* Determine if the user name and password entered are correct
*
* @param userId
* @param userpwd
* @return Account password Matching boolean value
*/
public boolean Checkpass (String userId, String userpwd) {
Boolean result = false;//
Properties Properties = new properties ();
try {
Properties.load (New FileInputStream ("./src/week6/bookmanagement/user.properties"));
if (Userid.equals (Properties.get ("UserId")) && userpwd.equals (Properties.get ("Userpwd")) {
result = true;
}
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return result;
}
/**
* Displays books when Isall is true, displays all books, otherwise displays the available books
*
* @param books
* A list of books greater than 0
* @param isall
* Displays full List of Books for department
*/
public void Showbooks (Arraylist<book> books, Boolean isall) {
int result = 0;//The number of books that can be loaned is initially 0book Book;
for (int i = 0; i < books.size (), i++) {
book = Books.get (i);
if (!isall) {
if (book.getstatus () = = 0) {
result++;
System.out.println ("Book ID:" + book.getbookid () + "\ T" + "title:" + book.getbookname () + "\ T" + ""
+ book.getauthor () + "\ T" + "Price:" + book.getprice ());
}
if (result = = 0) {
System.out.println ("I'm sorry, I can't borrow a book, all the books have been borrowed!") ");
}
} else {
System.out.println ("Book ID:" + book.getbookid () + "\ T" + "title:" + book.getbookname () + "\ T" + ""
+ bo Ok.getauthor () + "\ T" + "Price:" + book.getprice ());
}
}
}
/**
* Modify the status of a book
*
* @param Books
* A book list
* @param bookID
* Book ID to be modified
* @param status
* The status of the book to be modified, 0--return; the
* @return modified List of Books
*/
Public arraylist<book> Changestaus (arraylist<book > Books, String bookID, int status) {
int result = 0;
Book book;
for (int i = 0; i < books.size (), i++) {
book = Books.get (i);
The Action
if (Book.getbookid (). Equals (BookID) && book.getstatus ()! = status) exists when the book is present and the state is inconsistent with the passed state {
Book.setstatus (status);
Books.set (i, book);
Writelog (book, status);
result = 1;
}
}
if (result = = 1) {
System.out.println ("Operation succeeded! ");
} else {
System.out.println ("The operation failed! ");
}
return books;
}
/**
* Record log in and out of books
*
* @param book
* Books
* @param status
* The original state of the book, 0--is being returned;
*/
private void Writelog (book book, int status) {
File File = new file ("./src/week6/bookmanagement/booklog.txt");
FileOutputStream stream;
Calendar date = new GregorianCalendar ();
SimpleDateFormat SDF = new SimpleDateFormat ("yyyy mm month DD Day HH:mm:ss");
String time = Sdf.format (Date.gettime ());
String t = "lent";
if (status = = 0) {
t = "return";
}
try {
stream = new FileOutputStream (file, true);
byte[] bytes = (time+t+ "<<" + book.getbookname () + ">>" + "\ n"). GetBytes ();
Stream.Write (bytes);
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
Book Management Console program---help class