首页 > 编程语言 >Java实现:图书管理系统,附完整代码

Java实现:图书管理系统,附完整代码

时间:2024-07-21 18:54:53浏览次数:15  
标签:Java name 管理系统 System book println public 图书 out

目录

一、菜单

 二、基本框架

1.book包

1.1 book类

1.2 bookList类

2.use包

2.1 User类

 2.2 AdminUser类

2.3 NormalUser类

 2.4 用户菜单

3.opera包

3.1 IOperation接口

3.2 AddIOperation类

3.3 剩余类如下

4.Main类

4.1 login方法

4.2 main函数

 三、具体运行

3.1 ExitIOperation类

3.2 ShowIOperation类

3.3 AddIOperation类

3.4 BorrowedIOperation类

3.5 ReturnIoperation类

3.6 DelIoperation类

 总代码

book包

opera包

use包


一、菜单

该图书管理系统的菜单界面主要有以下两种:

 二、基本框架

1.book包

因为是图书管理系统,所以可以先从书(book)这个包开始。

book包中有book类和bookList类

1.1 book类

在book类中存放中图书的各种属性,书名、作者、价格、种类、借出状态。

    private String name;
    private String autor;
    private int price;
    private String type;
    private boolean isBorrowed;

再生成对应的构造方法:(Alt + insert) + Construct+(Crtl+鼠标)

                                       鼠标右键 + Generate + Construct+(Crtl+鼠标)

 生成以下代码:

public Book(String name, String autor, int price, String type) {
        this.name = name;
        this.autor = autor;
        this.price = price;
        this.type = type;
    }

再生成对应属性的get和set方法:(Alt + insert)+ Getter and Setter +(Crtl+鼠标)

 生成以下代码: 

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAutor() {
        return autor;
    }

    public void setAutor(String autor) {
        this.autor = autor;
    }

    public int 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;
    }

 最后再重写toString方法:(Alt + insert)+ toString() +(Crtl+鼠标) 

其中isBorrowed可以改写为下面三位运算符的形似: 

 

1.2 bookList类

bookList类更像是一个书架,书是放在里面的。先创建Book数组,同时可以用useSized来记录图书数量。同时也可以放三本书在书架里面,方便后面运行功能。

    private Book[] books = new Book[10];
    private int useSized = 0;

    public BookList(){
        this.books[0] = new Book("三国演义","罗贯中",15,"小说");
        this.books[1] = new Book("西游记","吴承恩",14,"小说");
        this.books[2] = new Book("红楼梦","曹雪芹",15,"小说");

        this.useSized = 3;
    }

再生成useSized的get和set方法:(Alt + insert) + Getter and Setter +(Crtl+鼠标)

 public int getUseSized() {
        return useSized;
    }

    public void setUseSized(int useSized) {
        this.useSized = useSized;
    }

2.use包

写完部分book包的内容,我们可以开始写use包、用户方面的内容。从一开始的菜单可以得知,用户分为管理员和普通用户。而这两者之间有一些相同的属性:都有菜单,都有用户姓名。所以可以写一个User来被它们继承。

ues包中有User类、AdminUser类和NormalUser类

2.1 User类

为了保证name权限合理性,对应的访问修饰限定符为protected

同时生成对应的构造方法:(Alt + insert) + Construct+ 鼠标

public  class User {
    protected String name;

    public User(String name) {
        this.name = name;
    }
}
 2.2 AdminUser类

AdminUser类继承(extends)User类,所以要在AdminUser中构造方法要重写User中的构造方法

对应构造方法的生成:(Alt + insert)+ Overr Methodes + 鼠标

public class AdminUser extends User{

    public AdminUser(String name) {
        super(name);
    }
}   
2.3 NormalUser类

同AdminUser类,步骤同上

public class NormalUser extends User{

    public NormalUser(String name) {
        super(name);
    }
}   
 2.4 用户菜单

考虑到 AdminUser类和NormalUser类都有各自对应的菜单,所以可以把User类写成抽象类。同时里面写抽线方法menu。

public abstract class User {
    protected String name;
    public IOperation[] iOperations;

    public User(String name) {
        this.name = name;
    }

    public abstract int meun();
}

 因为User类变为抽象类,其中有抽象方法menu,AdminUser类和NormalUser类要对meun进行重写,同时添加各自的界面

AdminUser类

public class AdminUser extends User{

    public AdminUser(String name) {
        super(name);
      
    }

    @Override
    public int meun() {
        System.out.println("**********");
        System.out.println("1.查找图书");
        System.out.println("2.新增图书");
        System.out.println("3.删除图书");
        System.out.println("4.显示图书");
        System.out.println("0.退出系统");
        System.out.println("**********");
        System.out.println("请输入需要的操作:");        
    }
}

NormalUser类

public class NormalUser extends User{

    public NormalUser(String name) {
        super(name);
        
    }

    @Override
    public int meun() {
        System.out.println("**********");
        System.out.println("1.查找图书");
        System.out.println("2.借阅图书");
        System.out.println("3.归还图书");
        System.out.println("0.退出系统");
        System.out.println("**********");
        System.out.println("请输入需要的操作:");               
    }

3.opera包

在写完book包和use包的部分内容后,我们可以开始来写不同用户所对应的功能

opera包中有AddIOperation类、BorrowedIOperation类、DelIOperation类、ExitIOperation类、

FindIOperation类、IOperation接口、ReturnIOperation类、ShowIOperation类。

3.1 IOperation接口

在创建class文件时,选择Interface,创建接口

 并在其中创建work方法

public interface IOperation {
    void work(BookList bookList);
}
3.2 AddIOperation类

 AddIOperation类去使用IOperation接口(implements)。

其中需要重写work方法:(Alt + insert)+ Overr Methodes + 鼠标

 然后对其中的内容进行重写:

public class AddIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书...");
    }
}
3.3 剩余类如下

步骤同上:接口 + 重写方法。

BorrowedIOperation类

public class BorrowedeIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书...");
    }
}

DelIOperation类

public class DelIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书...");
}

ExitIOperation类

public class ExitIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("退出系统...");
}

FindIOperation类

public class FindIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("查阅图书...");
}

ReturnIOperation类

public class ReturnIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书...");
}

ShowIOperation类

public class ReturnIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书...");
}

4.Main类

上面的框架搭建的差不多了,现在可以写Main主函数来进行运行。

4.1 login方法

既然要运行该框架,那就需要一个方法来进行,这里创建出login方法来进行

开始界面的思路时:输入姓名,输入是什么类型的用户,并返回对应的菜单

public static User login(){
        System.out.println("请输入你的姓名:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("请输入你的身份:1.管理员  2.普通成员");
        int choice = sc.nextInt();

        if(choice == 1){
            return new AdminUser(name);
        }else{
            return new NormalUser(name);
        }
    }
4.2 main函数

接下来通过login方法进行登录

public class Main {
    public static User login(){
        System.out.println("请输入你的姓名:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("请输入你的身份:1.管理员  2.普通成员");
        int choice = sc.nextInt();

        if(choice == 1){
            return new AdminUser(name);
        }else{
            return new NormalUser(name);
        }
    }

    public static void main(String[] args) {
        BookList bookList = new BookList();
        User user = login();
        while(true){
            int choice = user.meun();

        }
    }
}

此时通过调试可以发现,最后输出的需求并不能直接实现

要想,输入 1,返回查找图书,我们还需要两个步骤:

  1. 完善管理员菜单和普通用户菜单
  2. 在User类里添加 doIOperation方法。

 对于完善各自对应的菜单,我们能想到:如何使输入数字能进行对应的功能。

对应的功能可以放在一个数组里,然后通过数组下标进行输出。所以在User类添加

User类

public IOperation[] iOperations;

 在AdminUser类和NormalUser中也要有对应的改动

1.搭建ioperation数组

2.使菜单能返回输入的值

 AdminUser类

public class AdminUser extends User{

    public AdminUser(String name) {
        super(name);
        //1.搭建ioperation数组
        this.iOperations = new IOperation[]{
                new ExitIOperation(),
                new FindIOperation(),
                new AddIOperation(),
                new DelIOperation(),
                new ShowIOperation()
        };
    }

    @Override
    public int meun() {
        System.out.println("**********");
        System.out.println("1.查找图书");
        System.out.println("2.新增图书");
        System.out.println("3.删除图书");
        System.out.println("4.显示图书");
        System.out.println("0.退出系统");
        System.out.println("**********");
        //2.使菜单能返回输入的值
        System.out.println("请输入需要的操作:");
        Scanner sc = new Scanner(System.in);
        int choice = sc.nextInt();
        return choice;
    }
}
public class NormalUser extends User{

    public NormalUser(String name) {
        super(name);
        this.iOperations = new IOperation[]{
                new ExitIOperation(),
                new FindIOperation(),
                new BorrowedIOperation(),
                new ReturnIOperation()
        };
    }

    @Override
    public int meun() {
        System.out.println("**********");
        System.out.println("1.查找图书");
        System.out.println("2.借阅图书");
        System.out.println("3.归还图书");
        System.out.println("0.退出系统");
        System.out.println("**********");
        System.out.println("请输入需要的操作:");
        Scanner sc = new Scanner(System.in);
        int choice = sc.nextInt();
        return choice;
    }
}

完成上面步骤,我们可以获取输入值,接下来就可以写doIOperation方法来让打通这条路

因为这是用户所使用的,所以把它写在User类中

User类最终的User如下图所示:
 

public abstract class User {
    protected String name;
    public IOperation[] iOperations;

    public User(String name) {
        this.name = name;
    }

    public abstract int meun();

    public void doIOperation(int choice, BookList bookList){
        iOperations[choice].work(bookList);
    }
}

main方法为

public static void main(String[] args) {
        BookList bookList = new BookList();
        User user = login();
        while(true){
            int choice = user.meun();
            user.doIOperation(choice,bookList);
        }
    }

运行结果为:

 三、具体运行

3.1 ExitIOperation类

退出系统

在后面加 System.exit(0)。在程序运行后输入0便能退出循环,结束运行。

public class ExitIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("退出系统...");
        System.exit(0);
    }
}
3.2 ShowIOperation类

显示图书 

书是在书架上的,这就是说我们只要循环遍历书架便可以了。

其中可能存在的问题是不知道书架上有几本书,不过在一开始就创建了UsedSized来确定书本数。

为了能输出书,我们需要实例化书架上的书,但书架被private修饰,这时在BookList类里添加就需要get和set方法

BookList类

    public void setBooks(Book[] books) {
        this.books = books;
    }

    public Book[] getBooks(){
        return books;
    }

这是IDEA生成的get和set方法,仔细看其中和我们的需求并不一样,我们需要每一本书,而不是这个书架本身,所以可以改为下面的内容

   public Book getBook(int pos) {
        return books[pos];
    }

    public void setBook(int pos,Book book) {
        this.books[pos] = book;
    }

 最后,应用for循环来遍历书架上的每一本书

public class ShowIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("显示图书...");
        int currentSize =bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            System.out.println(book);
        }
    }

}
3.3 AddIOperation类

新增图书

新增图书可以分为四步:

  1. 判断书架是否放满
  2. 输入这本书的信息
  3. 判断书架里有没有这本书
  4. 插入这本书

其中主要是1.判断书架是否放满上面,我们需要在BookList类中添加getBooks方法,来获取数组的长度。

BookList类

public Book[] getBooks(){
        return books;
    }

AddIOperation类

public class AddIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {

        //1.判满
        int currentSize = bookList.getUseSized();
        if(currentSize == bookList.getBooks().length){
            System.out.println("书放满了");
        }

        //2.插入图书信息
        System.out.println("新增图书...");
        System.out.println("请输入书名:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("请输入作者:");
        String autor = sc.nextLine();
        System.out.println("请输入价格:");
        Scanner sc1 = new Scanner(System.in);
        int price = sc1.nextInt();
        System.out.println("请输入类型:");
        String type = sc.nextLine();

        Book newbook = new Book(name,autor,price,type);

        //3.判断书架有没有这本书
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("书架里有这本书,不能插入");
                return;
            }
        }

        //4.插入这本书
        bookList.setBook(currentSize,newbook);
        bookList.setUseSized(currentSize + 1);
        System.out.println("新增图书成功");
    }
}
3.4 BorrowedIOperation类

借阅图书

通过书名来借阅图书,通过遍历数组中的书来确定

  1. 是否有这本书
  2. 是否被借阅
public class BorrowedIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书...");
        System.out.println("请输入要借阅的图书:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);


            if(book.getName().equals(name)){
                if(book.isBorrowed() == true){
                    System.out.println("该图书已被借阅");
                    return;
                }

                book.setBorrowed(true);
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有你要借阅的图书");
    }
}
3.5 ReturnIoperation类

归还图书

归还图书的整体逻辑和借阅图书的类似,通过代码也能看出这一点

ublic class ReturnIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书...");
        System.out.println("请输入你要归还的图书:");
        Scanner sc =  new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed() == false){
                    System.out.println("该图书未被借阅,不能归还");
                    return;
                }

                book.setBorrowed(false);
                System.out.println("归还成功");
            }
        }

    }

}
3.6 DelIoperation类

删除图书

删除图书的思路大致如下

  1. 遍历书架来找到这本书
  2. 找到即开始删除这本书
public class DelIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书...");
        System.out.print("请输入要删除的图书:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();

        int pos = -1;//pos用来记录找到图书的下标
        //1.找到这本书
        int i = 0;
        for (; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                pos = i;
                break;
            }
        }

        if(i == currentSize){
            System.out.println("没有你要删除的图书");
            return;
        }

        //2.开始删除图书
        for (int j = pos; j < currentSize - 1; j++) {
            //j < currentSize - 1,如果只是currentSize,会越界
            //bookList[j] = bookList[j+1];
            Book book = bookList.getBook(j+1);//创建一个book对象,里面放book【j+1】
            bookList.setBook(j,book);
        }
        bookList.setUseSized(currentSize -1);
        System.out.println("删除成功");
    }
}

 总代码

book包

Book类

package book;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-07-14
 * Time: 14:07
 */
public class Book {
    private String name;
    private String autor;
    private int price;
    private String type;
    private boolean isBorrowed;

    public Book(String name, String autor, int price, String type) {
        this.name = name;
        this.autor = autor;
        this.price = price;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAutor() {
        return autor;
    }

    public void setAutor(String autor) {
        this.autor = autor;
    }

    public int 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;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", autor='" + autor + '\'' +
                ", price=" + price +
                ", type='" + type + '\'' +
                ", " + (isBorrowed == true ? "已借出" :"未借出") +
                '}';
    }
}

 BookList类

package book;


public class BookList {
    private Book[] books = new Book[10];
    private int useSized = 0;

    public BookList(){
        this.books[0] = new Book("三国演义","罗贯中",15,"小说");
        this.books[1] = new Book("西游记","吴承恩",14,"小说");
        this.books[2] = new Book("红楼梦","曹雪芹",15,"小说");

        this.useSized = 3;
    }

    public int getUseSized() {
        return useSized;
    }

    public void setUseSized(int useSized) {
        this.useSized = useSized;
    }

    public Book getBook(int pos) {
        return books[pos];
    }

    public void setBook(int pos,Book book) {
        this.books[pos] = book;
    }

    public Book[] getBooks(){
        return books;
    }
}

opera包

IOperation接口

public interface IOperation {
    void work(BookList bookList);
}

AddIOperation类

package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class AddIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {

        //1.判满
        int currentSize = bookList.getUseSized();
        if(currentSize == bookList.getBooks().length){
            System.out.println("书放满了");
        }

        //2.插入
        System.out.println("新增图书...");
        System.out.println("请输入书名:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("请输入作者:");
        String autor = sc.nextLine();
        System.out.println("请输入价格:");
        Scanner sc1 = new Scanner(System.in);
        int price = sc1.nextInt();
        System.out.println("请输入类型:");
        String type = sc.nextLine();

        Book newbook = new Book(name,autor,price,type);

        //3.判断书架有没有这本书
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("书架里有这本书,不能插入");
                return;
            }
        }

        //4.插入这本书
        bookList.setBook(currentSize,newbook);
        bookList.setUseSized(currentSize + 1);
        System.out.println("新增图书成功");
    }
}

BorroweIOperation类

package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class BorrowedIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书...");
        System.out.println("请输入要借阅的图书:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);


            if(book.getName().equals(name)){
                if(book.isBorrowed() == true){
                    System.out.println("该图书已被借阅");
                    return;
                }

                book.setBorrowed(true);
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有你要借阅的图书");
    }
}

DelIOperation类

package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class DelIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书...");
        System.out.print("请输入要删除的图书:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();

        int pos = -1;//pos用来记录找到图书的下标
        //1.找到这本书
        int i = 0;
        for (; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                pos = i;
                break;
            }
        }

        if(i == currentSize){
            System.out.println("没有你要删除的图书");
            return;
        }

        //2.开始删除图书
        for (int j = pos; j < currentSize - 1; j++) {
            //j < currentSize - 1,如果只是currentSize,会越界
            //bookList[j] = bookList[j+1];
            Book book = bookList.getBook(j+1);//创建一个book对象,里面放book【j+1】
            bookList.setBook(j,book);
        }
        bookList.setUseSized(currentSize -1);
        System.out.println("删除成功");
    }
}

ExitIOperation类

package opera;

import book.Book;
import book.BookList;


public class ExitIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("退出系统...");
        System.exit(0);
    }
}

FindIOperation类

package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class FindIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("查阅图书...");
        System.out.println("输入要查找的图书:");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int currentSize = bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("有这本书");
                System.out.println(book);
                return;
            }
        }
        System.out.println("没有找到这本书");
    }
}

ReturnIOperation类

package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class ReturnIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书...");
        System.out.println("请输入你要归还的图书:");
        Scanner sc =  new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed() == false){
                    System.out.println("该图书未被借阅,不能归还");
                    return;
                }

                book.setBorrowed(false);
                System.out.println("归还成功");
            }
        }

    }

}

ShowIOperation类

package opera;

import book.Book;
import book.BookList;

public class ShowIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("显示图书...");
        int currentSize =bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            System.out.println(book);
        }
    }

}

use包

 User类

package use;
import book.BookList;
import opera.IOperation;


public abstract class User {
    protected String name;
    public IOperation[] iOperations;

    public User(String name) {
        this.name = name;
    }

    public abstract int meun();

    public void doIOperation(int choice, BookList bookList){
        iOperations[choice].work(bookList);
    }
}

AdminUser类

package use;

import opera.*;

import java.util.Scanner;


public class AdminUser extends User{

    public AdminUser(String name) {
        super(name);
        this.iOperations = new IOperation[]{
                new ExitIOperation(),
                new FindIOperation(),
                new AddIOperation(),
                new DelIOperation(),
                new ShowIOperation()
        };
    }

    @Override
    public int meun() {
        System.out.println("**********");
        System.out.println("1.查找图书");
        System.out.println("2.新增图书");
        System.out.println("3.删除图书");
        System.out.println("4.显示图书");
        System.out.println("0.退出系统");
        System.out.println("**********");
        System.out.println("请输入需要的操作:");
        Scanner sc = new Scanner(System.in);
        int choice = sc.nextInt();
        return choice;
    }
}

NormalUser类

package use;

import opera.*;

import java.util.Scanner;


public class NormalUser extends User{

    public NormalUser(String name) {
        super(name);
        this.iOperations = new IOperation[]{
                new ExitIOperation(),
                new FindIOperation(),
                new BorrowedIOperation(),
                new ReturnIOperation()
        };
    }

    @Override
    public int meun() {
        System.out.println("**********");
        System.out.println("1.查找图书");
        System.out.println("2.借阅图书");
        System.out.println("3.归还图书");
        System.out.println("0.退出系统");
        System.out.println("**********");
        System.out.println("请输入需要的操作:");
        Scanner sc = new Scanner(System.in);
        int choice = sc.nextInt();
        return choice;
    }
}

 这里是小川,祝你开心,不止今天。

标签:Java,name,管理系统,System,book,println,public,图书,out
From: https://blog.csdn.net/xiaochuan_bsj/article/details/140435331

相关文章

  • Java--集合
    1.list集合的三大实现Java提供了几种List接口的实现,包括:ArrayList:基于动态数组实现,提供快速随机访问。添加和删除元素可能较慢,因为可能需要数组复制。LinkedList:基于双向链表实现,提供快速的添加和删除操作,但随机访问速度较慢。Vector:和ArrayList类似,但它是同步的。Sta......
  • Java操作打印机打印PDF
    话不多说,直接上代码。首先jar包依赖:<dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.24</version></dependency> 用于从给定的FileInputStream中加载PDF文档,并通过打印对话框进行打印。若本地......
  • Java计算机毕业设计家庭装修套餐消费管理(开题报告+源码+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着人们生活水平的提高,家庭装修已成为现代家庭生活中不可或缺的一部分。然而,传统的家庭装修过程往往繁琐复杂,涉及多个环节和众多参与者,导致信息不对......
  • Java计算机毕业设计老来福平台(开题报告+源码+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着老龄化社会的加速到来,如何为老年人提供高质量、个性化的养老服务成为亟待解决的问题。传统的养老模式已难以满足老年人日益增长的需求,特别是在信......
  • Java计算机毕业设计浪漫屋婚纱影楼管理系统(开题报告+源码+论文)
    本系统(程序+源码)带文档lw万字以上 文末可获取一份本项目的java源码和数据库参考。系统程序文件列表开题报告内容研究背景随着婚礼文化的日益丰富与个性化需求的不断增长,婚纱影楼行业迎来了前所未有的发展机遇与挑战。传统的人工管理模式已难以满足高效、精准、个性化的服......
  • 推荐大家学习JAVA结合Al
    AI辅助下的Java学习计划目标设定-**初级阶段**:掌握Java基础语法,理解面向对象编程思想。-**进阶阶段**:熟练运用集合、多线程、网络编程等高级特性。-**实战项目**:完成至少两个综合项目,利用AI辅助提升代码质量和开发效率。-**理论深化**:深入学习Java虚拟机(JVM)原理、设......
  • JAVA中的方法
    什么是方法方法就是函数,由代码片段构成,用于实现特定的功能。方法的定义及调用方法包括两个部分:方法头和方法体。修饰符返回值类型方法名(参数类型参数名){​ 方法体​ return返回值;}publicstaticvoidmain(){max(10,20);}publicstaticintmax(inta,int......
  • java基于ssm+vue 药品网购平台
    1用户前台功能模块1.1前台首页前台首页详情页面:首页、药品信息、疫情常识、保健品推荐、个人中心、后台管理、购物车等操作。程序效果图如下图1所示:前台页面等内容,如图1所示。 1.2个人中心在前台页面查看个人中心用户注册、登录,程序效果图如下图2所示:图2个人中心信息......
  • Java 多线程
    文章目录一、概念二、实现方式2.1Thread类2.2Runnable接口三、常用方法3.1基本方法3.2线程优先级3.3守护线程3.4礼让线程3.5插队线程四、线程安全问题4.1同步代码块4.2同步方法4.3lock()五、线程生命周期一、概念在Java中,多线程是指在一个程序中同......
  • Java 网络编程
    文章目录一、概念二、网络编程三要素三、UDP通信3.1发送端3.2接收端3.3运行结果四、TCP通信4.1发送端4.2接收端4.3运行结果五、三次握手、四次挥手5.1三次挥手(建立连接)5.5四次挥手(数据完整)一、概念在Java中,网络编程指的是计算机之间通过网络来进行通......