当前位置: 首页 > news >正文

用心做电影的网站网站制作素材

用心做电影的网站,网站制作素材,个体工商户做网站能加地名吗,.net网站开发文档🤷‍♀️🤷‍♀️🤷‍♀️ 今天给大家分享一下Java实现一个简易的图书管理系统! 清风的个人主页🎉✏️✏️ 🌂c/java领域新星创作者 🎉欢迎👍点赞✍评论❤️收藏 😛&…

🤷‍♀️🤷‍♀️🤷‍♀️ 今天给大家分享一下Java实现一个简易的图书管理系统!

清风的个人主页🎉✏️✏️ 

🌂c/java领域新星创作者

🎉欢迎👍点赞✍评论❤️收藏

😛😛😛希望我的文章能对你有所帮助,有不足的地方还请各位看官多多指教,大家一起学习交流!

动动你们发财的小手,点点关注点点赞!在此谢过啦!哈哈哈!😛😛😛


目录

 一、找到抽象化的对象

1.书类

2.书架类

二、管理员与普通用户登录

三、实现的功能

1.查找图书

2.新增图书(管理员功能)

3.删除图书(管理员功能)

4.显示图书信息

5.退出系统

6.借阅图书(普通用户功能)

7.归还图书(普通用户功能)

四、main方法



图书管理系统源码链接-满船清梦压星河的Gitee

 

 一、找到抽象化的对象

1.书类

经过分析,我们可以知道,书可以抽象成一个类型。它的属性包括:书名,作者,价格,书的类型等等...我们就先以这些为例。为了保持封装性,我们把这些属性都设置成private修饰的。

下面是书类的定义代码:
这段代码包括一些构造函数以及设置书的属性、重写String函数等。

public class Book {private String name;private String author;private int price;private String type;private boolean isBorrowed;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}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;}public Book(String name, String author, int price, String type) {this.name = name;this.author = author;this.price = price;this.type = type;}@Overridepublic String toString() {return "Book{" +"name='" + name + '\'' +", author='" + author + '\'' +", price=" + price +", type='" + type + '\'' +((isBorrowed==true)?"已借出!":"未借出!") +'}';}
}

2.书架类

我们可以利用一个数组来存放这些书籍,并记录当前存放书籍的数量,为后续的增删查改做准备,同时初始化有三本书籍。

下面是代码:

public class BookList {private Book[] books;private int usedSize;//记录当前书架上实际存放的书的数量public BookList(){this.books=new Book[10];this.books[0]=new Book("三国演义","罗贯中",18,"小说");this.books[1]=new Book("西游记","吴承恩",28,"小说");this.books[2]=new Book("红楼梦","曹雪芹",35,"小说");this.usedSize=3;}//获取当前存放书籍数量public int getUsedSize() {return usedSize;}//设置存放书籍数量public void setUsedSize(int usedSize) {this.usedSize = usedSize;}//返回下标为pos的书籍public Book getBook(int pos){return books[pos];}//设置下标为pos位置的书籍为bookpublic void setBook(int pos,Book book){books[pos]=book;}//返回书籍这个数组public Book[] getBooks(){return books;}
}

二、管理员与普通用户登录

首先定义一个用户抽象类,再定义管理员与普通用户去继承抽象类并重写菜单方法。

下面是用户抽象类代码:

abstract public class User {protected String name;protected IOPeration[] ioPerations;public User(String name) {this.name = name;}public abstract int menu();public void doOperation(int choice, BookList bookList){ioPerations[choice].work(bookList);}
}

管理员类代码:

public class AdiminUser extends User{public AdiminUser(String name){super(name);this.ioPerations=new IOPeration[]{new ExitOperation(),new FindOperation(),new AddOperation(),new DelOperation(),new ShowOperation()};}public int menu(){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("*********************");Scanner scanner=new Scanner(System.in);System.out.println("请输入你的选择:>");int choice=scanner.nextInt();return choice;}
}

普通用户类代码:
 

public class NormalUser extends User{public NormalUser(String name){super(name);this.ioPerations=new IOPeration[]{new ExitOperation(),new FindOperation(),new BorrowedOperation(),new ReturnOperation()};}public int menu(){System.out.println("*******普通用户*******");System.out.println("1.查找图书");System.out.println("2.借阅图书");System.out.println("3.归还图书");System.out.println("0.退出系统");System.out.println("********************");Scanner scanner=new Scanner(System.in);System.out.println("请输入你的选择:>");int choice=scanner.nextInt();return choice;}
}

三、实现的功能

实现以下几个功能,可以定义一个接口,方便后续的相关操作。

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

1.查找图书

public class FindOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("查找图书>:");System.out.println("请输入要查找的书>:");Scanner scanner=new Scanner(System.in);String name=scanner.nextLine();//遍历这个数组int currentSize=bookList.getUsedSize();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("无此书!!!");}
}

2.新增图书(管理员功能)

public class AddOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("新增图书>:");int cunrrentSize=bookList.getUsedSize();if (cunrrentSize==bookList.getBooks().length){System.out.println("书架已满!");return;}Scanner scanner=new Scanner(System.in);System.out.println("输入要新增书籍>:");String name=scanner.nextLine();//检查数组当中有没有这本书for (int i = 0; i <cunrrentSize ; i++) {Book book1=bookList.getBook(i);if(book1.getName().equals(name)){System.out.println("该书已存放,无需新增!!!");return;}}System.out.println("输入书籍作者>:");String author=scanner.nextLine();System.out.println("输入书籍类型>:");String type=scanner.nextLine();System.out.println("输入书籍价格>:");int price=scanner.nextInt();Book book=new Book(name,author,price,type);bookList.setBook(cunrrentSize,book);bookList.setUsedSize(cunrrentSize+1);System.out.println("新增书籍成功!!!");}
}

3.删除图书(管理员功能)

public class AddOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("新增图书>:");int cunrrentSize=bookList.getUsedSize();if (cunrrentSize==bookList.getBooks().length){System.out.println("书架已满!");return;}Scanner scanner=new Scanner(System.in);System.out.println("输入要新增书籍>:");String name=scanner.nextLine();//检查数组当中有没有这本书for (int i = 0; i <cunrrentSize ; i++) {Book book1=bookList.getBook(i);if(book1.getName().equals(name)){System.out.println("该书已存放,无需新增!!!");return;}}System.out.println("输入书籍作者>:");String author=scanner.nextLine();System.out.println("输入书籍类型>:");String type=scanner.nextLine();System.out.println("输入书籍价格>:");int price=scanner.nextInt();Book book=new Book(name,author,price,type);bookList.setBook(cunrrentSize,book);bookList.setUsedSize(cunrrentSize+1);System.out.println("新增书籍成功!!!");}
}

4.显示图书信息

public class ShowOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("显示图书>:");int currentSize=bookList.getUsedSize();for (int i = 0; i < currentSize; i++) {Book book=bookList.getBook(i);System.out.println(book);}}
}

5.退出系统

public class ExitOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("退出系统>:");System.exit(0);}
}

6.借阅图书(普通用户功能)

public class BorrowedOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("借阅图书>:");/*** 1.你要借阅哪本书?* 2.你借阅的书存在吗?* 借阅的方式是什么?*/Scanner scanner=new Scanner(System.in);System.out.println("输入要借阅书籍>:");String name=scanner.nextLine();int currentSize=bookList.getUsedSize();int i = 0;for (; i <currentSize ; i++) {Book book=bookList.getBook(i);if(book.getName().equals(name)){book.setBorrowed(true);System.out.println("借阅成功!!!");return;}}if(i==currentSize){System.out.println("该书不存在,无法借阅!!!");}}
}

7.归还图书(普通用户功能)

public class ReturnOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("归还图书>:");Scanner scanner=new Scanner(System.in);System.out.println("输入要归还书籍>:");String name=scanner.nextLine();int currentSize=bookList.getUsedSize();int i = 0;for (; i <currentSize ; i++) {Book book=bookList.getBook(i);if(book.getName().equals(name)){book.setBorrowed(false);System.out.println("归还成功!!!");return;}}if(i==currentSize){System.out.println("该书不存在,无需归还!!!");}}
}

四、main方法

public class Main {public static User login() {System.out.println("请输入你的姓名:>");Scanner scanner = new Scanner(System.in);String name = scanner.nextLine();System.out.println("请输入你的身份:> 1.管理员  2.普通用户");int choice = scanner.nextInt();if (choice == 1) {//管理员return new AdiminUser(name);} else {//普通用户return new NormalUser(name);}}public static void main(String[] args) {BookList bookList = new BookList();//user指向哪个对象,就看返回值是什么User user = login();while (true) {int choice = user.menu();System.out.println("choice:" + choice);//根据choice决定调用的是哪个方法user.doOperation(choice, bookList);}}
}

🎉好啦,今天的分享就到这里!!

创作不易,还希望各位大佬支持一下!

👍点赞,你的认可是我创作的动力!

收藏,你的青睐是我努力的方向!

✏️评论:你的意见是我进步的财富!

 

http://www.yayakq.cn/news/610954/

相关文章:

  • 莱芜益寿堂网站wordpress 保护wp-login.php
  • 建设一个网站需要考虑什么全球最好的设计网站
  • 长春网站建设兼职网站建设擎宇
  • 网站建设成功案例方案设计制作植物标识牌
  • 高端网站开发费用二维码生成器下载
  • 外贸出口公司网站建设方案微信小程序商城定制开发
  • wordpress threme岳阳关键词优化
  • 四川省住房和城乡建设厅网站下载卖域名的网站哪个好
  • 网站设计与网站制作医院设计机构
  • 网站建设话术分析wordpress代码恢复旧编辑器
  • 做贸易要看什么网站网店代运营正规公司
  • 平面设计哪个网站素材好腾讯企业邮箱登录入口网址
  • 运城做网站要多少钱门户网站建设的请示
  • 永州企业网站建设用区块链来做网站
  • 网站设计字体最好用晋城网站建设科技有限公司
  • 做网站需要板块wordpress手机端侧面小工具栏
  • php做电商网站安全性如何数字营销网站
  • 最新款淘宝客源码整网站程序模板+后台带自动采集商品功能带文章如何免费开网店
  • 网站怎么做uc整合求做网站
  • 泉州市建设工程质量监督站网站怎么做游戏和网站漏洞
  • 个人网站可以做充值辽宁建设工程信息网新点
  • 启动网站集约化建设某网站注册需要邮箱是怎么弄
  • 网站字体设计规范网站开发协议模版
  • 2018年网站建设发言电子商务网站 功能
  • 门户网站建设存在问题与不足在阿里云网站建设
  • 织梦网站搭建广州知名网站建设
  • asp.net做电商网站设计大连在哪个省市
  • 做物流的网站有哪些内容建设银行账户网站查询密码
  • 毕业设计如何用dw做网站泉州网络公司都
  • 海口市建设局网站校园网站的建设