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/03 Report--
This article will explain in detail how to use java to implement the library management system. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The details are as follows
Idea: all the packages are in the book_manage package
Many if-else judgments are removed by using object-oriented polymorphism, and different subclasses have different corresponding methods in the parent class.
1. First create a book package
There are two classes in the package, one is Book, which contains all the information about a book, and the other is BookList, which is used to manage each book and find each book through this class. Private Book [] books = new Book; the Book array holds all the books.
two。 Then create a package Operation this class has an OI interface, by rewriting the Work method in the interface to achieve the different operations of administrator identity and ordinary user identity.
3. Finally, create a User package with three classes, User,Admin,NormalUser
Both Admin and NormalUser inherit from User.User milliseconds you have an array of protected IO [] operation; that contains actions that users or administrators have. Determine the specific operation method that needs to be called by indexing the array.
Let's look at the code:
Book package
Book class
Package book_manager.book;public class Book {private String name; private String id; private String author; private int price; private String type; private boolean isBorrow; public Book (String name, String id, String author, int price, String type, boolean isBorrow) {this.name = name; this.id = id; this.author = author; this.price = price; this.type = type; this.isBorrow = isBorrow } @ Override / / Object built-in class to format the print book message public String toString () {return "Book {" name=' "+ name +'\'+", id=' "+ id +'\'+", author=' "+ author +'\'+", price= "+ price +", type=' "+ type +'\'+", isBorrow= "+ isBorrow +'}';} public String getName () {return name;} public boolean isBorrow () {return isBorrow } public void setBorrow (boolean bool) {this.isBorrow=bool;} public String getId () {return id;}}
BookList class
Package book_manager.book;import java.util.Arrays;public class BookList {private Book [] books = new Book [100]; private int size; public BookList () {books [0] = new Book (Jin Ping Mei, 001, Lan Ling Xiao Sheng, 100, Classical Masterpieces, false); books [1] = new Book (Water margin, 002, Shi Nai an, 100, Classical Masterpieces, false) Books [2] = new Book (Journey to the West, 003, Wu Chengen, 100, Classical classics, false); size= 3;} public int getSize () {return size;} public void setBooks (int index,Book book) {books [index] = book;} public void setSize (int size) {this.size=size;} public Book getBook (int index) {return books [index];}}
Operation package:
ADD class
Package book_manager.Operation;import book_manager.book.*;import java.util.Scanner;public class ADD implements IO {@ Override public void work (BookList bookList) {Scanner scanner = new Scanner (System.in); System.out.println ("Please enter the title"); String name = scanner.next (); System.out.println ("Please enter the serial number"); String id = scanner.next (); System.out.println ("Please enter the author"); String author = scanner.next () System.out.println ("Please enter price"); int price = scanner.nextInt (); System.out.println ("Please enter type"); String type = scanner.next (); Book book = new Book (name, id, author, price, type, false); bookList.setBooks (bookList.getSize (), book); bookList.setSize (bookList.getSize () + 1); System.out.println ("added successfully");}}
Borrow class
Package book_manager.Operation;import book_manager.book.Book;import book_manager.book.BookList;import java.util.Scanner;public class Borrow implements IO {@ Override public void work (BookList bookList) {int item0; int flag=0; Scanner scan = new Scanner (System.in); System.out.println ("Please enter the title of the book you need to borrow"); String name = scan.next (); for (; 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.