Java Programming (-----) Preliminary design of library management system

Source: Internet
Author: User

First draw the mind map, the right bottom of the user for the moment ...

First do book, abstract attributes, core functions. Then is the main function of drawing Bookmanager

Then directly export to eclipse for modification adjustments, the internal structure of the completion function is as follows:

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 * 2 4;private string Name;private string Isbn;private double price;private boolean lended;private int counter;private long len ddate;/** * Constructor */public Book (string ISBN, string name, double price) {THIS.ISBN = Isbn;this.name = Name;this.price = Pric E;this.counter = (int) (Math.random () * 50);} /** * Loan * * @return */public boolean lendout () {if (!lended) {lended = True;counter++;lenddate = System.currenttimemilli s (); return true;} return false;} /** * return * * @return */public double returnback () {if (lended) {lended = False;long currenttime = System.currenttimemilli s (); 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;} /** * Override the method of comparison */@Overridepublic int compareTo (book other) {return (other.counter-this.counter);} @Overridepublic String toString () {return "book [the_day=" + The_day + ", name=" + name + ", isbn=" + isbn+ ", price=" + p Rice + ", lended=" + lended + ", counter=" + Counter + ", lenddate=" + Lenddate + "]";}

Then the Manager, and finally a sort of verification

Package Com.lovo.bookmanager;import Java.util.arraylist;import Java.util.arrays;import java.util.List;import java.util.scanner;/** * @author Abe * @version 1.0 * @created 05-11 months -2011 15:58:35 */public class Bookmanager {private Lis t<book> list = new arraylist<book> ();p rivate Scanner sc = new Scanner (system.in);p ublic Bookmanager () {//Add Book As test data List.add (new book ("123-3344-567-89", "Java programming idea", 1.5)) List.add (new book ("123-4455-987-65", "Deer ding kee", 0.5)); List.add (new book ("321-3344-777-89", "Parenting encyclopedia", 1.2)), List.add (new book ("222-3344-555-89", "Qin Dynasty", 0.7)); List.add (new Book ("333-3344-666-89", "Bucket Continent", 1.1)); /** * Method: New Books * * @param book */public boolean Add (FINDBYISBN (BOOK.GETISBN ()) = = null) {List.add Turn true;} return false;} /** * * @param ISBN */public boolean deletebyisbn (String ISBN) {if (FINDBYISBN (ISBN) = = null) {return false;} else {list. Remove (FINDBYISBN (ISBN)); return true;}} /** * Get ALL Books * * @return */public list<book> findAll () {return List;}/** * Find Target Books by ISBN * * @param ISBN */public Book findbyisbn (String ISBN) {to (book b:list) {B.GETISBN (). Equals (ISBN); re Turn B;} return null;} @SuppressWarnings ("null") public list<book> FindTop10 () {if (List.size () < 2) {return List;} else {book[] Tempboo K = new Book[list.size ()];for (int i = 0; i < list.size (); i++) {Tempbook[i] = List.get (i);} Arrays.sort (Tempbook); list<book> temp = new arraylist<book> (); for (int i = 0; i < tempbook.length && I < ten i++) {tem P.add (Tempbook[i]);} return temp;}} /** * return * * @param b * @return rent */public double getbackfromuser (book B) {return b.returnback ();} /** * Loan * * @param b * @return whether to borrow a book successfully */public Boolean lendedtouser (book B) {return b.lendout ();} /** * Modify Content * * @param book */public void upDate (Book B) {Boolean goon = false;do {System.out.print ("What is the item you need to modify? 1 title 2nd 3 leases "); int i = Sc.nextint (); if (i = = 1) {System.out.print (" Please enter "+ b.getname () +" To change the new name: "); String name = Sc.nextline (); B.setname (name);} else if (i = = 2) {System.out.print ("Please enter a new price to change to:");d ouble prices = sc.nextdouble (); b.setprice;} else if (i = = 3) {System.out.print ("Please enter the number of new leases to be changed (not too much oh ~ Pro):"); int counter = Sc.nextint (); B.setcounter (counter);} else {System.out.println ("incorrect input");} System.out.println ("Would you like to continue to modify other projects?") y/n "); String answer = Sc.nextline (), if (Answer.equals ("Y")) {Goon = true;} else if (Answer.equals ("n")) {goon = false;}} while (goon); Sc.close ();} public static void Main (string[] args) {Bookmanager temp = new Bookmanager (), for (book X:TEMP.FINDTOP10 ()) {SYSTEM.OUT.P RINTLN (x);}}}



Java Programming (-----) Preliminary design of library management system

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.