当前位置:网站首页>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
边栏推荐
- 机械硬盘和ssd固态硬盘的原理对比分析
- Why must Oracle cloud customers self test after the release of Oracle cloud quarterly update?
- 基于 xml 配置文件的入门级 SSM 框架整合
- 如何使用200行代码实现Scala的对象转换器
- Axi bus
- Cesium realizes satellite orbit detour
- Crane: a new way of dealing with dictionary items and associated data
- Yuweng information, a well-known information security manufacturer, joined the dragon lizard community to build an open source ecosystem
- Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan
- Rereading the classic: the craft of research (1)
猜你喜欢

CMOS级电路分析

Embedded development: embedded foundation callback function

Debug tool

Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan

芯片供给过剩之际,进口最多的中国继续减少进口,美国芯片慌了

新华三的千亿企业梦,还得靠吃ICT老本来实现?

Does Xinhua San still have to rely on ICT to realize its 100 billion enterprise dream?

SFINAE

【业务安全-02】业务数据安全测试及商品订购数量篡改实例

重读经典:《The Craft of Research(1)》
随机推荐
高效率取幂运算
Debug tool
After the deployment is created, the pod problem handling cannot be created
关于接口测试自动化的总结与思考
初识云原生安全:云时代的最佳保障
ENSP cloud configuration
基于 Nebula Graph 构建百亿关系知识图谱实践
[day 27] given an integer n, print out the full permutation from 1 to n | Full Permutation template
Kyndryl partnered with Oracle and Veritas
Dynamic Networks and Conditional Computation论文简读和代码合集
crane:字典项与关联数据处理的新思路
What is the difference between the FAT32 and NTFS formats on the USB flash disk
JVM performance tuning and monitoring tools -- JPS, jstack, jmap, jhat, jstat, hprof
跨境电商多商户系统怎么选
MySQL index and its classification
Pytorch learning 3 (test training model)
NAACL 2022 | TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
buuctf misc 百里挑一
Bidding announcement: Oracle database maintenance service procurement of the First Affiliated Hospital of Jinan University
MySQL 索引及其分类