当前位置:网站首页>Library management system
Library management system
2022-06-27 13:53:00 【Xiao Wei likes fried wool】
import book.BookList;
2 import user.AdminUser;
3 import user.NormalUser;
4 import user.User;
5
6 import java.util.Scanner;
7
8 /**
9 * Created with IntelliJ IDEA.
10 * Description:
11 * User: WHY
12 * Date: 2022-06-24
13 * Time: 19:40
14 */
15 public class Main {
16 public static User login(){
17 System.out.println(" Please enter your name ");
18 Scanner scanner=new Scanner(System.in);
19 String name= scanner.nextLine();
20
21 System.out.println(" Please enter your identity :1:-》 Administrators ,0:—》 Ordinary users ");
22 int choice=scanner.nextInt();
23 if(choice==1){
24 return new AdminUser(name);
25 }
26 else{
27 return new NormalUser(name);
28 }
29 }
30 public static void main(String[] args) {
31 // Start integrating
32 BookList booklist=new BookList();// Prepare books
33
34 // Sign in
35 User user=login();// Equivalent to upward transformation
36 user.menu();
37 int choice = user.menu();// Dynamic binding
38 user.doOperation(choice,booklist);
39 }
40 }
+74 2022.6.24/2022.6.24/src/book/Book.java 0 → 100644
1 package book;
2
3 /**
4 * Created with IntelliJ IDEA.
5 * Description:
6 * User: WHY
7 * Date: 2022-06-24
8 * Time: 18:00
9 */
10 public class Book {
11 private String name;
12 private String author;
13 private int price;
14 private String type;
15 private boolean isBorrowed;
16
17 public Book(String name, String author, int price, String type) {
18 this.name = name;
19 this.author = author;
20 this.price = price;
21 this.type = type;
22 }
23
24 public String getName() {
25 return name;
26 }
27
28 public void setName(String name) {
29 this.name = name;
30 }
31
32 public String getAuthor() {
33 return author;
34 }
35
36 public void setAuthor(String author) {
37 this.author = author;
38 }
39
40 public int getPrice() {
41 return price;
42 }
43
44 public void setPrice(int price) {
45 this.price = price;
46 }
47
48 public String getType() {
49 return type;
50 }
51
52 public void setType(String type) {
53 this.type = type;
54 }
55
56 public boolean isBorrowed() {
57 return isBorrowed;
58 }
59
60 public void setBorrowed(boolean borrowed) {
61 isBorrowed = borrowed;
62 }
63
64 @Override
65 public String toString() {
66 return "Book{" +
67 "name='" + name + '\'' +
68 ", author='" + author + '\'' +
69 ", price=" + price +
70 ", type='" + type + '\'' +
71 ", isBorrowed=" + isBorrowed +
72 '}';
73 }
74 }
+49 2022.6.24/2022.6.24/src/book/BookList.java 0 → 100644
1 package book;
2
3 /**
4 * Created with IntelliJ IDEA.
5 * Description:
6 * User: WHY
7 * Date: 2022-06-24
8 * Time: 18:01
9 */
10 public class BookList {
11
12 private Book[] books=new Book[20];
13 private int usedSize;// Record the current in real time books How many books are there in this array
14
15
16 public BookList(){
17 books[0]=new Book(" White night line "," Guiwu Dongye ",60," Suspense reasoning ");
18 books[1]=new Book(" Criminal suspect X The dedication of "," Guiwu Dongye ",80," Suspense reasoning ");
19 books[2]=new Book(" The blade of hesitation "," Guiwu Dongye ",120," Suspense reasoning ");
20 usedSize=3;
21
22 }
23 // According to the position of the book , Get this book
24 public Book getBook(int pos){
25 return books[pos];
26 }
27 /*
28 * New books ,POS Is the place to put
29 * book It's the book you want to put
30 * */
31 public void setBooks( int pos , Book book){
32 books[pos]=book;
33 }
34 /*
35 *
36 * Get the number of current books in real time
37 *
38 * */
39 public int getUsedSize(){
40 return usedSize;
41 }
42 /*
43 * Modify the number of books on the current shelf in real time
44 *
45 * */
46 public void setUsedSize(int size){
47 usedSize=size;
48 }
49 }
+17 2022.6.24/2022.6.24/src/operation/AddOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 18:54
11 */
12 public class AddOperation implements IOperation {
13 @Override
14 public void work(BookList booklist) {
15 System.out.println(" New books ");
16 }
17 }
+17 2022.6.24/2022.6.24/src/operation/BorrowOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 19:01
11 */
12 public class BorrowOperation implements IOperation{
13 @Override
14 public void work(BookList booklist) {
15 System.out.println(" Borrow books ");
16 }
17 }
+17 2022.6.24/2022.6.24/src/operation/DelOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 18:57
11 */
12 public class DelOperation implements IOperation{
13 @Override
14 public void work(BookList booklist) {
15 System.out.println(" Delete books ");
16 }
17 }
+17 2022.6.24/2022.6.24/src/operation/ExitOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 19:00
11 */
12 public class ExitOperation implements IOperation{
13 @Override
14 public void work(BookList booklist) {
15 System.out.println(" Exit the system ");
16 }
17 }
+17 2022.6.24/2022.6.24/src/operation/FindOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 18:56
11 */
12 public class FindOperation implements IOperation {
13 @Override
14 public void work(BookList booklist) {
15 System.out.println(" Look for books ");
16 }
17 }
+15 2022.6.24/2022.6.24/src/operation/IOperation.java 0 → 100644
1 package operation;
2
3 import book.Book;
4 import book.BookList;
5
6 /**
7 * Created with IntelliJ IDEA.
8 * Description:
9 * User: WHY
10 * Date: 2022-06-24
11 * Time: 18:48
12 */
13 public interface IOperation {
14 void work(BookList booklist);
15 }
+19 2022.6.24/2022.6.24/src/operation/ReturnOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 19:02
11 */
12 public class ReturnOperation implements IOperation{
13 ;
14
15 @Override
16 public void work(BookList booklist) {
17 System.out.println(" Return books ");
18 }
19 }
+17 2022.6.24/2022.6.24/src/operation/ShowOperation.java 0 → 100644
1 package operation;
2
3 import book.BookList;
4
5 /**
6 * Created with IntelliJ IDEA.
7 * Description:
8 * User: WHY
9 * Date: 2022-06-24
10 * Time: 18:59
11 */
12 public class ShowOperation implements IOperation{
13 @Override
14 public void work(BookList booklist) {
15 System.out.println(" Show books ");
16 }
17 }
+43 2022.6.24/2022.6.24/src/user/AdminUser.java 0 → 100644
1 package user;
2
3 import operation.*;
4
5 import java.util.Scanner;
6
7 /**
8 * Created with IntelliJ IDEA.
9 * Description:
10 * User: WHY
11 * Date: 2022-06-24
12 * Time: 19:17
13 */
14 public class AdminUser extends User{
15 public AdminUser(String name) {
16 super(name);
17 this.iOperations = new IOperation[]{
18 new ExitOperation(),
19 new FindOperation(),
20 new AddOperation(),
21 new DelOperation(),
22 new ShowOperation(),
23
24
25
26 };
27 }
28 public int menu(){
29 System.out.println("hello"+this.name+" Welcome to the book exercise !");
30 System.out.println("1. Look for books !");
31 System.out.println("2. New books !");
32 System.out.println("3. Delete books !");
33 System.out.println("4. Show books !");
34 System.out.println("0. Exit the system !");
35 System.out.println(" Please enter your operation ");
36 Scanner scanner=new Scanner(System.in);
37 int choice = scanner.nextInt();
38 return choice;
39
40
41 }
42
43 }
+40 2022.6.24/2022.6.24/src/user/NormalUser.java 0 → 100644
1 package user;
2
3 import operation.*;
4
5 import java.util.Scanner;
6
7 /**
8 * Created with IntelliJ IDEA.
9 * Description:
10 * User: WHY
11 * Date: 2022-06-24
12 * Time: 19:16
13 */
14 public class NormalUser extends User {
15 public NormalUser(String name) {
16 super(name);
17 this.iOperations = new IOperation[]{
18 new ExitOperation(),
19 new FindOperation(),
20 new BorrowOperation(),
21 new ReturnOperation(),
22
23
24
25 };
26 }
27 public int menu(){
28 System.out.println("hello"+this.name+" Welcome to the book exercise !");
29 System.out.println("1. Look for books !");
30 System.out.println("2. Borrow books !");
31 System.out.println("3. Return books !");
32 System.out.println("0. Exit the system !");
33 System.out.println(" Please enter your operation ");
34 Scanner scanner=new Scanner(System.in);
35 int choice = scanner.nextInt();
36 return choice;
37
38
39 }
40 }
+27 2022.6.24/2022.6.24/src/user/User.java 0 → 100644
1 package user;
2
3 import book.BookList;
4 import operation.IOperation;
5
6 /**
7 * Created with IntelliJ IDEA.
8 * Description:
9 * User: WHY
10 * Date: 2022-06-24
11 * Time: 19:06
12 */
13 abstract public class User {
14 protected String name;// user name
15
16 public User(String name) {
17 this.name = name;
18 }
19 public abstract int menu();
20 protected IOperation[] iOperations ;//
21 public void doOperation(int choice, BookList booklist){
22 this.iOperations[choice].work(booklist);
23
}
24
25
26
27 }
package operation;
2 2
3 import book.Book;
3 4 import book.BookList;
4 5
6 import java.util.Scanner;
7
5 8 /**
6 9 * Created with IntelliJ IDEA.
7 10 * Description:
@@ -13,5 +16,30 @@ public class DelOperation implements IOperation{
13 16 @Override
14 17 public void work(BookList booklist) {
15 18 System.out.println(" Delete books ");
19 Scanner scanner=new Scanner(System.in);
20 System.out.println(" Please enter the name of the deleted book :");
21 String name= scanner.nextLine();
22 int currentSize= booklist.getUsedSize();
23 int index=-1;
24 int i =0;
25 for (; i <currentSize ; i++) {
26 Book book=booklist.getBook(i);
27 if(book.getName().equals(name)){
28 index=i;
29 break;
30 }
31 }
32
33 if(i>=currentSize){
34 System.out.println(" I didn't find the book ");
35 return;
36 }
37 for(int j=index;j<currentSize ;j++){
38 Book book=booklist.getBook(i+1);
39 booklist.setBooks(i,book);
40 }
41 booklist.setBooks( currentSize-1,null);// Deleted books , Moved , Then set the last one as empty , There will be no memory leaks
42 booklist.setUsedSize(currentSize-1);
43 System.out.println(" Delete successful ");
16 44 }
17 45
}The above is the realization of the library management system , We will discuss the specific ideas in the next issue
边栏推荐
- 清华&商汤&上海AI&CUHK提出Siamese Image Modeling,兼具linear probing和密集预测性能!...
- Interviewer: do you understand redis' shared object pool?
- Rereading the classic: the craft of research (1)
- 美国芯片再遭重击,继Intel后又一家芯片企业将被中国芯片超越
- 图书管理系统
- [daily 3 questions (3)] maximum number of balls in the box
- [WUSTCTF2020]girlfriend
- crane:字典项与关联数据处理的新思路
- Shell concise tutorial
- After 2 years of outsourcing, I finally landed! Record my ByteDance 3 rounds of interviews, hope to help you!
猜你喜欢

Cesium realizes satellite orbit detour

The second part of the travel notes of C (Part II) structural thinking: Zen is stable; all four advocate structure

Openssf security plan: SBOM will drive software supply chain security

【微服务|Sentinel】热点规则|授权规则|集群流控|机器列表

基于 xml 配置文件的入门级 SSM 框架整合
![[XMAN2018排位赛]通行证](/img/eb/7bf04941a96e9522e2b93859266cf2.png)
[XMAN2018排位赛]通行证

ensp云朵配置

Kyndryl与Oracle和Veritas达成合作
![[business security 03] password retrieval business security and interface parameter account modification examples (based on the metinfov4.0 platform)](/img/29/73c381f14a09ecaf36a98d67d76720.png)
[business security 03] password retrieval business security and interface parameter account modification examples (based on the metinfov4.0 platform)

请求一下子太多了,数据库危
随机推荐
Dynamic Networks and Conditional Computation论文简读和代码合集
Interviewer: do you understand redis' shared object pool?
关于接口测试自动化的总结与思考
命令行编辑器 sed 基础用法总结
【OS命令注入】常见OS命令执行函数以及OS命令注入利用实例以及靶场实验—基于DVWA靶场
A statistical problem of shell script
线程同步之信号量
每日3题(1):找到最近的有相同 X 或 Y 坐标的点
MySQL index and its classification
enable_ if
解析Activity启动-生命周期角度
awk 简明教程
海外仓知识科普
微服务如何拆分
Implementation of recruitment website based on SSM
爱可可AI前沿推介(6.27)
芯片供给过剩之际,进口最多的中国继续减少进口,美国芯片慌了
一道shell脚本的统计题
Firewall foundation Huawei H3C firewall web page login
[problem solving] which nodes are run in tensorflow?