In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will introduce to you how to implement the library management system in JAVA. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
I. brief introduction
A simple project exercise after learning the basic syntax of Java syntax, such as classes, interfaces, inheritance, polymorphism, interfaces, etc.
The specific functions are:
1. Simple login based on name
2. Administrator side: its function is to consult books, add books, delete books, print books, organize books according to price, and exit.
3. Ordinary client: consult books, borrow books, return books, exit.
Achieve results:
Enter the user's name first, and then decide whether to be an administrator or a user according to your choice. If it is an administrator, it displays the administrator and its menu, and if it is a user, it displays the user's menu.
Second, the design of the system
The whole system is divided into four parts, which are implemented with three packages and a Main class respectively. They are Book package, Operation package and User package.
1. Book package:
Contains book, bookList. Two java files
Book is used to describe the characteristics of each book.
BookList means the whole bookshelf.
1.1.Books: package Book;/** * @ author * / public class book {private String name; private String author; private double price; private String type; private boolean isBorrowed; public String getName () {return name;} public void setName (String name) {this.name = name;} public String getAuthor () {return author } public void setAuthor (String author) {this.author = author;} public double getPrice () {return price;} public void setPrice (int price) {this.price = price;} public String getType () {return type;} public void setType (String type) {this.type = type;} public boolean isBorrowed () {return isBorrowed } public void setBorrowed (boolean borrowed) {isBorrowed = borrowed;} public book (String name, String author, double price, String type) {this.name = name; this.author = author; this.price = price; this.type = type } @ Override public String toString () {return "book {" + "name='" + name +'\'+ ", author='" + author +'\'+ ", price=" + price + ", type='" + type +'\'+ ((isBorrowed==true)? "lent": "not lent") +'}';} public double compare (book o1jingheado2) {return o1.getPrice ()-o2.getPrice ();} 1.2.Booklist: package Book;/** * @ author spicy mushroom gluten * / public class bookList {private book [] books=new book [10]; private int usedSize Public bookList () {books [0] = new book ("A hundred years of Solitude", "Garcia M á rquez", 39.60, "novel"); books [1] = new book ("Silent confession", "Wu Yi Shi", 35.00, "novel"); books [2] = new book (Meditation, Marco Olle, 32.00, "philosophy") Books [3] = new book ("data structure and algorithm", "Wang Qin", 45.00, "textbook"); this.usedSize=4;} / * * legal and unfilled are not currently considered * default to the last * @ param pos * @ param book * / public void setBooks (int pos,book book) {this.books [pos] = book } public book getBook (int pos) {return this.books [pos];} public int getUsedSize () {return usedSize;} public void setUsedSize (int usedSize) {this.usedSize = usedSize;} public book [] getBooks () {return this.books;}} 2, Operation package:
Write the operation as an interface. Let each method inherit this interface later
The Operation package contains all the methods for both identities. First implement all the class methods in the package. Among the administrators and ordinary users who are specifically integrated into the User package. Include these methods in an array.
2.1. Add books:
Adding books will prompt the administrator to enter the information that needs to be added step by step. If the book is already used on the shelf, it will not be added to the shelf.
Package Opreation;import Book.bookList;import Book.book;import java.util.Scanner;public class AddOperation implements IOperaion {@ Override public void work (bookList bookList) {System.out.println ("New Book"); Scanner scanner=new Scanner (System.in); System.out.println ("enter the name of the new book"); String name=scanner.nextLine (); System.out.println ("enter the author of the book") String Authorname=scanner.nextLine (); System.out.println (enter the type of book); String sype=scanner.nextLine (); System.out.println (enter the price of the book); int price=scanner.nextInt (); int currentSize=bookList.getUsedSize (); for (int I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.