Java Programming (14.1)-----The preliminary design of library Management system internal function chapter

Source: Internet
Author: User

First, draw a mind map. The user on the right is temporarily no matter the first ...

Do book first. Abstract properties, core functionality.

Then is the main function of drawing Bookmanager

Then export directly to eclipse to make changes, complete the internal structure of the feature such as the following:

Package Com.lovo.bookmanager;import java.sql.date;import java.text.simpledateformat;/** * @author Abe * @version 1.0 * @c reated 05-11 months -2011 15:58:35 */public class book implements comparable<book>{final long The_day = 1000 * 60 * 60 * 24 ;p rivate string Name;private string Isbn;private double price;private boolean lended;private int counter;private long lend date;/** * Constructor */public Book (string ISBN, string name, double price) {this.isbn = ISBN; this.name = name; this.price = pri Ce;this.counter = (int) (Math.random () * 50);} /** * Loan * @return */public boolean lendout () {if (!lended) {lended = True;counter++;lenddate = System.currenttimemillis () ; return true;} return false;} /** * return * @return */public double returnback () {if (lended) {lended = False;long currenttime = System.currenttimemillis () int days = (int) Math.ceil ((currenttime-lenddate)/the_day), lenddate = 0;return days * PRICE; return 0;} Public String GetName () {return name;} Public String GETISBN () {return ISBN;} Public double GetPrice () {return price;} public Boolean islended () {return lended;} public int Getcounter () {return counter;} /** * Loan Date * @return */public String getlenddate () {if (lended) {Date date = new Date (lenddate); SimpleDateFormat SDF = new SimpleDateFormat ("yyyy mm month DD day"); return Sdf.format (date);} else {return "---";}} public void SetName (String name) {this.name = name;} public void Setprice (double price) {this.price = Price;} public void Setcounter (int counter) {this.counter = counter;} /** * Rewrite the comparison method */@Overridepublic int compareTo (book other) {return (other.counter-this.counter);} @Overridepublic String toString () {return "name=" + name + ", isbn=" + isbn+ ", price=" + Price + ", lended=" + lended + ", counter=" + Counter + ", lenddate=" + Lenddate + "]";}}

And then the Manager.

Package Com.lovo.bookmanager;import java.util.arraylist;import Java.util.arrays;import java.util.List;/** * @author ABE * @version 1.0 * @created 05-11 months -2011 15:58:35 */public class Bookmanager {private list<book> List = new Arrayli St<book> ();p ublic Bookmanager () {//Add books as test data List.add (new book ("111", "programming Idea", 1.5)), List.add ("222", " Ding Lu, 0.5), List.add (new book ("333", "child-rearing encyclopedia", 1.2)), List.add ("444", "Qin", 0.7)), List.add (new book ("555", "bucket of the mainland ", 1.1));} /** * Method: New Books * @param book */public boolean Add (FINDBYISBN (BOOK.GETISBN ()) = = null) {List.add n true;} return false;} /** * Remove book * @param ISBN */public boolean deletebyisbn (String ISBN) {if (FINDBYISBN (ISBN) = = null) {return false;} else {L Ist.remove (FINDBYISBN (ISBN)); return true;}} /** * Method: Returns all containers * @return */public list<book> findAll () {return List;} /** * Find Target Books by ISBN * @param ISBN */public Book findbyisbn (String ISBN) {for (book b:list) {if (B.GETISBN (). Equals (ISBN)) {return B;}} return null;} Public book[] FindTop10 () {if (list! = null) {book[] Tempbook = new Book[list.size ()];tempbook = List.toarray (Tempbook); Arrays.sort (Tempbook); Anonymous inner class excuse abook[] Top10 = new Book[list.size () < List.size (): 10]; System.arraycopy (tempbook, 0, Top10, 0, top10.length); return top10;} else {return null;}} /** * return * @param b * @return rent */public Double Getbackfromuser (String ISBN) {if (FINDBYISBN (ISBN)! = null) {return FINDB YISBN (ISBN). returnback ();} return 0;} /** * Loan * @param b * @return whether to borrow books successfully */public Boolean Lendedtouser (String ISBN) {if (FINDBYISBN (ISBN) = null) {return fin DBYISBN (ISBN). lendout ();} return false;}}

3. Finally, the function verification of the console

Package Com.lovo.bookmanager;import java.util.list;import java.util.scanner;/** * @author Abe * @version 1.0 * @created 05 -November -2014 15:37:33 */public class Systemui {public static void main (string[] args) {Bookmanager manager = new Bookmanager ( ); Scanner SC1 = new Scanner (system.in); Scanner SC2 = new Scanner (system.in);d o {int choice = 0;do {System.out.println ("\ n---------------\ n"); System.out.println ("1. New book "); System.out.println ("2. Delete the book "); System.out.println ("3. Changes to the book "); System.out.println ("4. View all Books "); System.out.println ("5. Find books "); System.out.println ("6. Borrowing "); System.out.println ("7. Return "); System.out.println ("8. View Leaderboard "); System.out.println ("9. Exit system "); System.out.println ("\ n---------------\ n"); System.out.print ("Please select:"); choice = Sc2.nextint ();} while (Choice < 1 | | Choice > 9), switch (choice) {case 1:system.out.print ("Please enter the number of the book:"); String isbn1 = Sc1.nextline (); System.out.print ("Please enter the name of the book:"); String name = Sc1.nextline (); System.out.print ("Please enter the daily rent of the book:");d ouble price = Sc2.nextdouble (); Book Newbook = new book (ISBN1, Name, price); System.out.println (Manager.add (newbook)?

"Join succeeded!": "Join failed!"); Break;case 2:system.out.print ("Please enter the number of the book:"); String isbn2 = Sc1.nextline (); System.out.println (MANAGER.DELETEBYISBN (ISBN2)? "Delete succeeded!": "Delete failed!"); Break;case 3:break;case 4:list<book> Booklist = Manager.findall (); System.out.println ("name \t\t day rent \ t status \ t loan date \ t loan number"); for (book b:booklist) {System.out.println (B.getname () + "\t\t" + B.getprice () + "\ T" + (b.islended ()? "Borrowed": "Not Lent") + "\ T" +b.getlenddate () + "\ T" + b.getcounter ());} Break;case 5:system.out.print ("Please enter the number of the book:"); String isbn3 = Sc1.nextline (); Book temp = MANAGER.FINDBYISBN (ISBN3), if (temp! = null) {System.out.println ("title:" + Temp.getname ()); System.out.println ("Day Rent:" + temp.getprice ()); System.out.println ("Loan Status:" + (temp.islended ()? ") Borrowed ":" Not Lent)); System.out.println ("Loan Date:" + temp.getlenddate ()); System.out.println ("Number of loans:" + temp.getcounter ());} else {SYSTEM.OUT.PRINTLN ("!!! Without this book");} Break;case 6:system.out.print ("Please enter the number of the book:"); String isbn4 = Sc1.nextline (); System.out.println (Manager.lendedtouser (ISBN4)?

"Lend success!": "Loan failed!"); Break;case 7:system.out.print ("Please enter the number of the book:"); String isbn5 = Sc1.nextline (); SYSTEM.OUT.PRINTLN ("Please pay rent: ¥" + manager.getbackfromuser (isbn5)); break;case 8:book[] list = MANAGER.FINDTOP10 (); System.out.println ("name \t\t day rent \ t status \ t loan date \ t loan number"); for (book b:list) {System.out.println (B.getname () + "\t\t" + B.getprice () + "\ T" + (b.islended ()? "Borrowed": "Not Lent") + "\ T" +b.getlenddate () + "\ T" + b.getcounter ());} Break;case 9:system.exit (0); break;}} while (true);}}


Can execute normally except for changes



Java Programming (14.1)-----The preliminary design of library Management system internal function chapter

Related Article

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.