当前位置:网站首页>Implementation of a small book system
Implementation of a small book system
2022-06-25 13:20:00 【LIn_ jt】
On the implementation of a small book system
This is about the implementation of a Book System , First, let's look at its basic functions
First , This book system can distinguish you from a librarian , Or an ordinary user

In addition, depending on the choice , We can choose different functions , Select the panel we get from the manager

Select the panel we get from the students

First, let's look at its basic functions , For example, we show books :>

Or look for books

Next , We implement it step by step through code :>
First , Since it is a Book System , Then you must have books ?, Books have information such as names and authors , So we can create a Book Class , To store our information .
Book class

Here we state 5 Member variables , It's our name,author,type,price,isBorrowed, Explain the name of a Book , author , type , Price , Whether it has been lent out , Here, our access qualification modifier adopts private, In order to achieve a packaging effect .
Besides , We also need to provide a construction method , To initialize the book .

Here, in our construction method , Without our isBorrowed member , Because member variables have a default value when they are not initialized ,boolean When members of type are not initialized, the default value is false, We can understand it as not lending .
Since the member variable is private modification , We should provide... Accordingly get and set Method , To access these member variables

There's nothing to say here ,( If you want to type it quickly, you can use idea Shortcut keys )
There is another step !, That's rewriting our toString Method , So that we can print the books later :

BookList class
Now that there are books , Should there be a shelf for our books ? This is the time , We created a BookList class , To store my books , At the same time, get the information of each of our books

stay BookList In it, we define a Book An array of types bookList, Used to store every book we have . There is also a record of how many books are stored in the current array usedSized. We also use private To modify , To achieve the effect of packaging :>
Besides , We also provide a parameter free construction method , First pair bookList and usedSized To initialize .

Since arrays and usedSized By private modification , We should also provide get and set Method .

Here we're talking about arrays bookList Provided get and set Method , For a specific book in the array , Therefore, we are operating in the array , Like the second setPos, We have two parameters book and pos , book It's the book we want to keep , pos Is the subscript of the book we want to store .
A series of operations on the bookshelf
Now that there are books and shelves , The next step is to carry out a series of operations on the bookshelf , We put these operations in a package .

then , We divide the operations we need into various classes , For example, our operation of adding books , We can define it as a AddOperation class , For example, our book search operation , We can define it as a FindOperation class , We follow this line of thinking , Step by step .

ad locum , We have defined 7 Classes , increase , Borrow , Delete books and so on , Now let's look at the contents of its class ( With our AddOperation For example )

Here we write a work Method ( We haven't realized the specific content in it yet ), adopt work Methods let's add a Book , Then other operations , For example, our FindOperation, ExitOperation Operation, etc. , You can also pass a work Method to implement , In this case , We can define an interface , To regulate work The behavior in .

In this case , All operations can be used to implement this interface .
Take an example of one of these classes :>

User class
Besides , With our operation class , Next, our object should be our user object ? Users are divided into administrators and students , But from another point of view, they are also users , therefore , Here we will User Set as parent class , Put our managers -AdminUser, Student -NormalUser For its subclass , therefore , We can initially achieve ;
User class :>

Normal class

AdminUser class :>

In this way, we have preliminarily implemented such a user class .
MainClass
Next is the implementation of our main function , Since you want to enter a Book System , Then we must log in first, right ?, So let's first write a login Method


there login function , We choose the way , To identify you , Return an administrator or student object at the same time , Because they are User class , In fact, there is an upward transformation here .

Now that a subclass object is returned , We use it User Type of variable to receive . We want to , Should I print it after I accept it The corresponding menu ?, therefore , We can do it in User Add one to the class menu function , Let subclasses override it , In this case , You can go through user Call the corresponding menu !

Here we write a menu function , But we don't want it in User Class specifies its contents , therefore , We can set it as an abstract method , In this case ,User Class also becomes an abstract class :>

since User It becomes an abstract class , that AdminUser Classes and Normal Class to override the abstract method of the parent class :
AdminUser

NormalUser

In this case , We User Type of user quote , After referencing the subclass object , You can call the corresponding menu Method .


In this case , You can display the corresponding menu , But here it is , We're a little short Step , That's it , To enter the corresponding action . therefore , We still need to menu Make some changes in the function :>


We are going to menu The return value of the function is changed to int, In this way, these operations can be received
Now that the choice has been made , So should we consider who called the method corresponding to the administrator or the student ? The words here , There is an operation , That is , We are in our User Define an interface array in an abstract class .

But here , We did not specify the specified size of the array , This is because it is used to store our operations , The operation of the administrator is different from that of the students , therefore , We need to be in Normal Classes and AdminUser Class to initialize the array accordingly
Normal class 
AdminUser class

In this way, we get the corresponding method , The next step is to consider Who called it ?, There is also an operation here , That is to create a method , To call it , Next, let's look at an example :>

** Here we write a doOperaiton Method , It can ensure that who calls the method at the same time , You can also know exactly which method to call .** Next , We are right. MainClass Class :>

In this case , Our main framework has been written , What needs to be done next , That is to concretize our operation of bookshelves .
DisplayOperation
First , We will concretize the operation of the display book :.

Here, we first get the number of elements in the current array , And through our getPos( Get the books on the current shelf ), To print , Let's first look at the effect :>

So you ok 了 .
ExitOperation

First of all, let's recycle the resources here through the empty bookshelf , Then pass System.exit(), We pass it into a 0, It means that the program exits normally .
DelOperation
Before you get a specific deletion method , Let's start with an example :>




such , We have completed our deletion operation , Next, let's look at the specific code :>


Here we first enter the name of the book , To match the names in the bookshelf , then :>

Here we go through equals Method , Compare the names in the bookshelves one by one , So if you find it , We can do the... In our example , The next data replaces the previous data . Next, let's look at the effect :>

Deleted successfully !
FindOperation
Then there is a little copy and paste , Paste us DelOperation Operation of methods in class :>

If we find the book we want to borrow , We put its member variables isBorrowed Set as true that will do , Let's see the effect :>

Loan success !
ReturnOperation
The operation of returning books , It can be said that the operation is basically the same as that of borrowing books , It's just that we need to put the member variable isBorrowed Set as false that will do

Next, let's look at the effect :>

Successful return !
FindOperation
Or copy and paste for a while :>

Next, let's look at the effect :>

Successfully found the name of the book .
In this case , Our book system is complete . Post my gitee home page , The following is the source code of the book system .
边栏推荐
- Three lines of code to simply modify the project code of the jar package
- C# 切换中英文输入法
- QT mouse tracking
- Back test of quantitative trading - tqzfuturerenkowavestrategy
- Accidentally modify or delete the system variable path to restore
- 始终保持疫情防控不放松 营造安全稳定的社会环境
- [pit avoidance means "difficult"] the antd form dynamic form is deleted, and the first line is displayed by default
- 爱可可AI前沿推介(6.25)
- Nova组件源码分析之冷迁移与Resize
- 1251- client does not support authentication protocol MySQL error resolution
猜你喜欢
![[flask tutorial] flask overview](/img/e8/d85ac54f3a9eb3b1ab31852761154c.jpg)
[flask tutorial] flask overview

leetcode:剑指 Offer II 091. 粉刷房子【二维dp】

About data storage in memory

Detailed explanation of string operation functions and memory functions

数据在内存中的存储相关内容

Sword finger offer II 025 Adding two numbers in a linked list

字符串各操作函数与内存函数详解

KDD 2022 | graphmae: self supervised mask map self encoder

Seven competencies required by architects

KDD 2022 | GraphMAE:自监督掩码图自编码器
随机推荐
Used in time filter (EL table)
Accidentally modify or delete the system variable path to restore
OpenStack学习笔记(二)
leetcode:456. 132 模式【单调栈】
[flask tutorial] flask overview
Back test of quantitative trading - tqzfuturerenkowavestrategy
爱可可AI前沿推介(6.25)
.NET in China - What's New in .NET
Storage related contents of data in memory
关于一道教材题的讲解
Lexical trap
剑指Offer 第 2 天链表(简单)
golang键盘输入语句scanln scanf代码示例
[转]以终为始,详细分析高考志愿该怎么填
初始c语言的知识2.0
About data storage in memory
[pit avoidance means "difficult"] actionref current. Reload() does not take effect
Django framework - caching, signaling, cross site request forgery, cross domain issues, cookie session token
Regular match the phone number and replace the fourth to seventh digits of the phone number with****
. NET in China - What's New in . NET