采用JAVA设计一个小型图书管理程序(只要增删查改)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了采用JAVA设计一个小型图书管理程序(只要增删查改)相关的知识,希望对你有一定的参考价值。
采用JAVA设计一个小型图书管理程序,具有信息添加、查询、修改和删除功能。图书信息包括: 图书编号,书名,作者名,分类号,出版单位,出版时间,价格。
用eclipse编写然后连接到数据库,能正常运行出现图形用户界面实现增删查改四个功能就行了,谢谢了,可以发到我邮箱2194215481@qq.com。
私了
参考技术D /***
*/
package com.java.lanqiao.action;
/**
* @author mayj
*Title:Demo
*date:2017年12月14日 下午12:51:41
*/
import java.util.Random;
import java.util.Scanner;
public class Demo
public static void main(String[] args)
Book b = new Book();
b.init();
b.menu();
class Book
private String bookName;
private String bookState;
private int bookNums;
private int bookPrice;
static int count = 0;
Book()
public String getBookName()
return bookName;
public void setBookName(String bookName)
this.bookName = bookName;
public String getBookState()
return bookState;
public void setBookState(String bookState)
this.bookState = bookState;
public int getBookNums()
return bookNums;
public void setBookNums(int bookNums)
this.bookNums = bookNums;
public int getBookPrice()
return bookPrice;
public void setBookPrice(int bookPrice)
this.bookPrice = bookPrice;
Book[] book = new Book[10];
Scanner in = new Scanner(System.in);
Random r = new Random();
public void init()
for (int i = 0; i < 3; i++)
book[i] = new Book();
/*System.out.println();
for (int i = 0; i < 3; i++)
book[i].bookName = in.next();
*/
book[0].bookName = "aaa";
book[1].bookName = "sss";
book[2].bookName = "ddd";
for (int i = 0; i < 3; i++)
book[i].bookNums = r.nextInt(10)+1;
count ++;
for (int i = 0; i < 3; i++)
book[i].bookState = "在库";
for (int i = 0; i < 3; i++)
book[i].bookPrice = r.nextInt(50)+30;
public void lookBook()
System.out.println("\n书名 库存 价格 状态");
for (int i = 0; i < count; i++)
System.out.println(book[i].bookName+" "+book[i].bookNums+" "+book[i].bookPrice+" "+book[i].bookState);
public void addBook()
String name;
Book newBook = new Book();
System.out.print("请输入书名:");
name = in.next();
newBook.bookName = name;
book[count] = newBook;
book[count].bookName = newBook.bookName;
book[count].bookState = "在库";
book[count].bookNums = r.nextInt(10)+1;
book[count].bookPrice = r.nextInt(50)+30;
count ++;
System.out.println("添加成功!!!");
lookBook();
public void deleteBook()
System.out.print("请输入需要删除的图书:");
String name;
name = in.next();
for (int i = 0; i < count; i++)
if( book[i].bookName.equals(name) )
if(book[i].bookState.equals("在库"))
count --;
int index = i;
while(book[index+1] != null)
book[index] = book[index+1];
index ++;
System.out.println("删除成功!!!");
break;
else
System.out.println("该图书不在馆内,不能删除");
else if(!book[i].bookName.equals(name))
System.out.println("没有找到"+name+"这本书!!!");
lookBook();
public void lendBook()
System.out.print("请输入要借阅的图书名称:");
String naem = in.next();
for (int i = 0; i < count; i++)
if( book[i].bookName.equals(naem) && book[i].bookNums > 0)
System.out.println("借书成功!!!");
book[i].bookNums --;
break;
else
System.out.println("你想借阅的书不在书库内!!!");
lookBook();
public void returnBook()
System.out.print("请输入需要归还的图书名称:");
String naem = in.next();
for (int i = 0; i < count; i++)
if( book[i].bookName.equals(naem))
System.out.println("还书成功!!!");
book[i].bookNums ++;
break;
else
System.out.println("该书不是书库内的书,还书失败!!!");
lookBook();
public void modifyBook()
System.out.print("请输入要修改图书的图书名称:");
String name = in.next();
System.out.print("请输入要修改图书的图书状态:");
String status = in.next();
System.out.print("请输入要修改图书的图书数量:");
int nums = in.nextInt();
System.out.print("请输入要修改图书的图书价格:");
int price = in.nextInt();
for (int i = 0; i < count; i++)
if(book[i].bookName.equals(name))
book[i].bookState = status;
book[i].bookNums = nums;
book[i].bookPrice = price;
System.out.println("图书信息修改成功!!!");
break;
else
System.out.println("修改失败!!!");
lookBook();
public void rank()
Book temp = new Book();
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++)
if(book[i].bookNums < book[j].bookNums)
temp = book[i];
book[i] = book[j];
book[j] = temp;
lookBook();
public void menu()
Scanner in = new Scanner(System.in);
String s = null;
do
System.out.println("\n---------------- 图书管理系统 ----------------\n");
System.out.println(" 1 查看图书");
System.out.println(" 2 增加图书");
System.out.println(" 3 删除图书");
System.out.println(" 4 借阅图书");
System.out.println(" 5 归还图书");
System.out.println(" 6 修改图书");
System.out.println(" 7 图书排行");
System.out.println(" 0 退出系统");
System.out.print("\n请输入你的选择:");
int n = in.nextInt();
switch (n)
case 1:
lookBook();
break;
case 2:
addBook();
break;
case 3:
deleteBook();
break;
case 4:
lendBook();
break;
case 5:
returnBook();
break;
case 6:
modifyBook();
break;
case 7:
rank();
break;
case 0:
System.exit(0);
break;
default:
System.out.println("输入有误!!!");
break;
System.out.println("\n是否继续 ? ( y / n)");
s = in.next();
while(s.equals("y") || s.equals("Y"));
ElasticSearch 7.3采用restful风格 基本的增删查改语句
1 、新建图书索引
首先建立图书索引 book
语法:put /index
PUT /book
结果
2、新增图书 :新增文档
语法:PUT /index/type/id
PUT /book/_doc/1 "name": "Bootstrap开发", "description": "Bootstrap是由Twitter推出的一个前台页面开发css框架,是一个非常流行的开发框架,此框架集成了多种页面效果。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长css页面开发的程序人员)轻松的实现一个css,不受浏览器限制的精美界面css效果。", "studymodel": "201002", "price":38.6, "timestamp":"2019-08-25 19:11:35", "pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg", "tags": [ "bootstrap", "dev"] PUT /book/_doc/2 "name": "java编程思想", "description": "java语言是世界第一编程语言,在软件开发领域使用人数最多。", "studymodel": "201001", "price":68.6, "timestamp":"2019-08-25 19:11:35", "pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg", "tags": [ "java", "dev"] PUT /book/_doc/3 "name": "spring开发基础", "description": "spring 在java领域非常流行,java程序员都在用。", "studymodel": "201001", "price":88.6, "timestamp":"2019-08-24 19:11:35", "pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg", "tags": [ "spring", "java"]
结果
3、查询图书:检索文档
语法:GET /index/type/id
查看图书:
GET /book/_doc/1
就可看到json形式的文档。方便程序解析。
为方便查看索引中的数据,kibana可以如下操作
Kibana-discover- Create index pattern- Index pattern填book
下一步,再点击discover就可看到数据。点击json还可以看到原始数据
4、修改图书:替换操作
PUT /book/_doc/1 "name": "Bootstrap开发教程1", "description": "Bootstrap是由Twitter推出的一个前台页面开发css框架,是一个非常流行的开发框架,此框架集成了多种页面效果。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长css页面开发的程序人员)轻松的实现一个css,不受浏览器限制的精美界面css效果。", "studymodel": "201002", "price":38.6, "timestamp":"2019-08-25 19:11:35", "pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg", "tags": [ "bootstrap", "开发"]
替换操作是整体覆盖,要带上所有信息。
5、 修改图书:更新文档
语法:POST /index/type /id/_update
或者POST /index/_update/id
POST /book/_update/1/ "doc": "name": " Bootstrap开发教程高级"
返回:
6、删除图书:删除文档
语法:
DELETE /book/_doc/1
返回:
本文来自博客园,作者:|旧市拾荒|,转载请注明原文链接:https://www.cnblogs.com/xiaoyh/p/15969579.html
以上是关于采用JAVA设计一个小型图书管理程序(只要增删查改)的主要内容,如果未能解决你的问题,请参考以下文章