Book Management Console program---help class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.