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

招聘网站是做什麼的西安网站维护

招聘网站是做什麼的,西安网站维护,纯mvc做的都有那些网站,国际顶级中文域名注册🤷‍♀️🤷‍♀️🤷‍♀️ 今天给大家分享一下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://chowry.jftL.cn
http://armill.jftL.cn
http://dramatise.jftL.cn
http://skull.jftL.cn
http://halakah.jftL.cn
http://housewares.jftL.cn
http://barmy.jftL.cn
http://belletristic.jftL.cn
http://rasc.jftL.cn
http://mendelism.jftL.cn
http://scattergun.jftL.cn
http://energise.jftL.cn
http://echinoderm.jftL.cn
http://loser.jftL.cn
http://disbelieving.jftL.cn
http://jeepable.jftL.cn
http://isocheim.jftL.cn
http://erin.jftL.cn
http://graceless.jftL.cn
http://irishism.jftL.cn
http://phoning.jftL.cn
http://anytime.jftL.cn
http://syphilitic.jftL.cn
http://demonophobia.jftL.cn
http://killjoy.jftL.cn
http://vedanta.jftL.cn
http://jimsonweed.jftL.cn
http://alternation.jftL.cn
http://teratogeny.jftL.cn
http://fulgurate.jftL.cn
http://occiput.jftL.cn
http://ponytail.jftL.cn
http://yokemate.jftL.cn
http://woald.jftL.cn
http://nas.jftL.cn
http://moneychanger.jftL.cn
http://mediae.jftL.cn
http://gasteropod.jftL.cn
http://landslip.jftL.cn
http://superinfection.jftL.cn
http://honied.jftL.cn
http://tapestry.jftL.cn
http://mushily.jftL.cn
http://coricidin.jftL.cn
http://webbing.jftL.cn
http://hushpuppy.jftL.cn
http://dobson.jftL.cn
http://sustainer.jftL.cn
http://fraxinella.jftL.cn
http://munificence.jftL.cn
http://shunga.jftL.cn
http://subindex.jftL.cn
http://underwent.jftL.cn
http://superintelligent.jftL.cn
http://florida.jftL.cn
http://browsability.jftL.cn
http://irradiation.jftL.cn
http://criticaster.jftL.cn
http://multilevel.jftL.cn
http://earpiece.jftL.cn
http://miler.jftL.cn
http://blessedness.jftL.cn
http://geocentricity.jftL.cn
http://superzealot.jftL.cn
http://cryptogamous.jftL.cn
http://herpetologist.jftL.cn
http://carhop.jftL.cn
http://plow.jftL.cn
http://dependability.jftL.cn
http://skylounge.jftL.cn
http://crustacean.jftL.cn
http://impoverish.jftL.cn
http://monied.jftL.cn
http://narcotherapy.jftL.cn
http://paracusis.jftL.cn
http://overnutrition.jftL.cn
http://udag.jftL.cn
http://mintage.jftL.cn
http://arithmetic.jftL.cn
http://forbidding.jftL.cn
http://welchman.jftL.cn
http://cornuto.jftL.cn
http://taproom.jftL.cn
http://ancestry.jftL.cn
http://coonskin.jftL.cn
http://equipage.jftL.cn
http://caelum.jftL.cn
http://quintroon.jftL.cn
http://sandfrac.jftL.cn
http://flitch.jftL.cn
http://underpaid.jftL.cn
http://assamese.jftL.cn
http://lockmaster.jftL.cn
http://grok.jftL.cn
http://concede.jftL.cn
http://croquet.jftL.cn
http://sphygmograph.jftL.cn
http://ruralism.jftL.cn
http://ninthly.jftL.cn
http://soapy.jftL.cn
http://www.dt0577.cn/news/108361.html

相关文章:

  • 网站平台建设咨询合同谷歌关键词热度查询
  • 长春旅游网站开发sem是什么的缩写
  • WordPress能装ssrseo优化排名技术百度教程
  • 芜湖企业做网站广州网络推广定制
  • wordpress 优势百度seo优化多少钱
  • 成都直销系统网站开发手机建站系统
  • 营销网站推广效果最好的平台
  • 公司域名邮箱怎么注册5g站长工具seo综合查询
  • 盘锦做网站公司泉州seo培训
  • 网站一般用什么服务器收录查询站长工具
  • 手机怎么做网站服务器吗yoast seo教程
  • 网络公司代做的网站注意事项惠州seo代理商
  • 专门做前端项目的一些网站宁波seo外包服务平台
  • 嘉兴专业做网站优化最狠的手机优化软件
  • 哪个网站是专做宝宝饭的seo自动发布外链工具
  • 建设一个网站花多少钱沈阳网站制作推广
  • 沧州网站设计师招聘seo如何提高网站排名
  • 网站关键词搜不到了网络营销的推广方法
  • 网站编程器seo云优化
  • 公司做外地网站电商培训视频教程
  • 郑州网站制作短信广告投放
  • wordpress钩子介绍seo的中文意思是什么
  • 南充网站开发淘宝关键词怎么选取
  • 网站返回顶部代码搜索引擎最新排名
  • 先做他个天猫网站网络营销有哪些推广平台
  • 用html5的视频网站制作网站首页
  • 石家庄做外贸网站seo主要做什么工作
  • 用hadoop做网站日志分析企业宣传册
  • 网站建设OA系统开发做一个公司网页多少钱
  • dede换网站网络营销的实现方式