「java中图书查询的功能」java中图书查询的功能是什么
本篇文章给大家谈谈java中图书查询的功能,以及java中图书查询的功能是什么对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、JAVA版的图书管理系统
- 2、利用Java实现图书的借阅管理功能,采用文本文件方式存储数据自行设计数据结构。
- 3、查询图书信息:按名字查询图书 (Java图书管理系统) 按上架日期查询 按种类查询
- 4、用java编写一个简单的图书管理系统。 要求:实现浏览,借书,还书,查询,退出等功能(每次最多能借
JAVA版的图书管理系统
送你一份代码,结构大致按照你的需求了,自己增加一些小功能,不会的话请教你同学。
分给我,钱就不用了。
#include string.h
#define FORMAT "\n%-8d%-8d%-7d%-8d%-7d%-8d%-10s%-9s%-9s\n"
#include stdio.h
#include conio.h
#include malloc.h
#define NULL 0
#define N 100
#define LEN sizeof(struct book)
int M;
struct book
{int Enum;
int Cnum;
char name[10];
char author[10];
char publishor[30];
struct date
{int year;
int month;
int day;}time;
int price;
struct book*next;
}go[N];
void print()
{printf("---------------------------------------------------------------------------\n");
printf("Enum Cnum year month day price name author publishor\n");
printf("---------------------------------------------------------------------------\n");
}
void load()
{FILE *fp;
int i;
if((fp=fopen("book_list","rb"))==NULL)
{printf("cannot open file\n");
return;
}
i=0;
while((fread(go[i],sizeof(struct book),1,fp))!=NULL)
{i++;}
M=i;
fclose(fp);
}
void save(int h)
{FILE *fp;
int i;
if ((fp=fopen("BOOK_LIS","wb"))==NULL)
{printf("cannot open file\n");
return;
}
for (i=0;ih;i++)
if(fwrite(go[i],sizeof(struct book),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void f1()
{FILE *fp;
int i=0;
fp=fopen("book_list","rb");
print();
while((fread(go[i],sizeof(struct book),1,fp))!=NULL)
{printf(FORMAT,go[i].Enum,go[i].Cnum,go[i].time.year,go[i].time.month,go[i].time.day,go[i].price,go[i].name,go[i].author,go[i].publishor);
i++;
}
fclose(fp);
getch();
}
void f2(int h)
{int i;
printf("please input %d book's information\n",h);
printf("Enum Cnum year month day price name author publishor\n");
for(i=0;ih;i++)
{printf("Enum:\n");
scanf("%d",go[i].Enum);
printf("Cnum:\n");
scanf("%d",go[i].Cnum);
printf("please input year month day\n");
scanf("%d%d%d",go[i].time.year,go[i].time.month,go[i].time.day);
printf("price:\n");
scanf("%d",go[i].price);
printf("name:\n");
scanf("%s",go[i].name);
printf("author:\n");
scanf("%s",go[i].author);
printf("publishor:\n");
scanf("%s",go[i].publishor);
}
save(h);
return;
}
void f3()
{int i;
struct book;
char a[20],b[20],c[20];
load();
printf("please input 'name' or 'author':\n");
scanf("%s",a);
if(strcmp(a,"name")==0)
{printf("please input the book's name:\n");
scanf("%s",b);
for(i=0;iM;i++)
if(strcmp(b,go[i].name)==0)
{print();
printf(FORMAT,go[i].Enum,go[i].Cnum,go[i].time.year,go[i].time.month,go[i].time.day,go[i].price,go[i].name,go[i].author,go[i].publishor);
}
}
else
{printf("please input the book's author:\n");
scanf("%s",c);
for(i=0;iM;i++)
if(strcmp(c,go[i].author)==0)
{print();
printf(FORMAT,go[i].Enum,go[i].Cnum,go[i].time.year,go[i].time.month,go[i].time.day,go[i].price,go[i].name,go[i].author,go[i].publishor);
}
}
return;
}
void f4()
{int i,j,k;
struct book t;
load();
for(i=0;iM;i++)
{k=i;
for(j=i+1;jM;j++)
if(go[k].pricego[j].price)k=j;
t=go[i];go[i]=go[k];go[k]=t;
}
print();
for(i=0;iM;i++)
printf(FORMAT,go[i].Enum,go[i].Cnum,go[i].time.year,go[i].time.month,go[i].time.day,go[i].price,go[i].name,go[i].author,go[i].publishor);
}
void f5()
{FILE *fp;
int i,j,M,flag;
char name[10];
if((fp=fopen("book_list","rb"))==NULL)
{printf("cannot open file\n");
return;
}
printf("\norriginal data:\n");
print();
for(i=0;fread(go[i],sizeof(struct book),1,fp)!=0;i++)
printf(FORMAT,go[i].Enum,go[i].Cnum,go[i].time.year,go[i].time.month,go[i].time.day,go[i].price,go[i].name,go[i].author,go[i].publishor);
M=i;
printf("\n input the deleted name:\n");
scanf("%s",name);
for(flag=1,i=0;flagiM;i++)
{if(strcmp(name,go[i].name)==0)
{for(j=i;jM-1;j++)
{go[j].Enum=go[j+1].Enum;
go[j].Enum=go[j+1].Enum;
strcpy(go[j].name,go[j+1].name);
strcpy(go[j].author,go[j+1].author);
strcpy(go[j].publishor,go[j+1].publishor);
go[j].time.year=go[j+1].time.year;
go[j].time.month=go[j+1].time.month;
go[j].time.day=go[j+1].time.day;
go[j].price=go[j+1].price;
}
flag=0;
}
}
if(!flag)
M=M-1;
else
printf("not found!\n");
printf("\nNow,the content of file:\n");
fp=fopen("book_list","wb");
for(i=0;iM;i++)
fwrite(go[i],sizeof(struct book),1,fp);
fclose(fp);
fp=fopen("book_list","wb");
for(i=0;fread(go[i],sizeof(struct book),1,fp)!=0;i++);
printf(FORMAT,go[i].Enum,go[i].Cnum,go[i].time.year,go[i].time.month,go[i].time.day,go[i].price,go[i].name,go[i].author,go[i].publishor);
fclose(fp);
}
main()
{int i,h;
clrscr();
while(1)
{printf ("\n 1 is a project that can output all information.\n");
printf ("\n 2 is a project that can add any book's information.\n");
printf ("\n 3 is a project that can search information.\n");
printf ("\n 4 is a project that can sort.\n");
printf ("\n 5 is a project that can del.\n");
printf ("\n 6 is a project that can leave.\n");
printf("please input number:1 or 2 or 3 or 4 or 5 or 6\n");
scanf("%d",i);
switch (i)
{case 1:f1();break;
case 2:
{printf ("if you want to add book's information,please input a data:h=");
scanf("%d",h);
f2(h);}break;
case 3:
{f3();getch();}break;
case 4:{f4();getch();}break;
case 5:{f5();getch();}break;
case 6:exit (1);
}
clrscr();}
}
利用Java实现图书的借阅管理功能,采用文本文件方式存储数据自行设计数据结构。
//只实现了图书的添加
package com.suncheng.main;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
//路径
private final static String PATH = "D:\\";
//图书录入.txt
private final static String TSLR = PATH+"图书录入.txt";
//人员信息.txt
private final static String RYXX = PATH+"人员信息.txt";
//借还书.txt
private final static String JS_HS = PATH+"借还书.txt";
static{
try {
String[][] arr = {{"图书ID,图书名称",TSLR},{"人员ID,姓名",RYXX},{"借还ID,借书人,开始借书时间,最终还书截至时间,还书时间,是否已还",JS_HS}};
for(int i = 0; i arr.length; i++){
getTitle(arr[i][0], arr[i][1]);
}
} catch (IOException e) {
throw new RuntimeException("系统出现问题,请联系管理员!");
}
}
{
try {
init();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
new Main();
}
//初始化菜单
private void init() throws IOException{
System.out.println("++++++++++++借书管理系统++++++++++++");
System.out.println("\t1). 图书的录入");
System.out.println("\t2). 人员信息的录入");
System.out.println("\t3). 图书的查询");
System.out.println("\t4). 借书的录入");
System.out.println("\t5). 还书的录入");
System.out.println("\t6). 人员借阅信息的显示");
System.out.println("请输入相应菜单:");
try {
int num = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
switch(num){
case 1 :
getTSLR();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
//通用添加标题方法
private static void getTitle(String split,String path) throws IOException{
String[] arr = split.split(",");
BufferedWriter out = new BufferedWriter(new FileWriter(path));
for(int i = 0; i arr.length; i++){
out.write(arr[i]+"\t");
}
out.newLine();
out.close();
}
//添加图书方法
private boolean getTSLR() throws IOException{
boolean flag = false;
FileWriter fw = new FileWriter(this.TSLR,true);
BufferedReader br = getSystem_In();
while(true){
System.out.println("请输入图书ID");
String id = br.readLine();
System.out.println("请输入图书姓名");
String name = br.readLine();
fw.write(id+"\t");
fw.write(name+"\t");
fw.write("\r\n");
System.out.println("是否继续添加 Y、N");
if(!"y".equalsIgnoreCase(br.readLine())){
break;
}
}
fw.close();
br.close();
return flag;
}
private BufferedReader getSystem_In(){
return new BufferedReader(new InputStreamReader(System.in));
}
}
//图书类
class Book{
private int id; //图书ID
private String name; //图书名称
}
//人员类
class Person{
private int id; //人员ID
private String name; //姓名
}
//借还信息类
class Person_Book{
private int id; //借还ID
private String person; //借书人
private String startDate; //开始借书时间
private String stopDate; //最终还书截至时间
private String hsDate; //还书时间
private boolean flag; //是否已还 true还,false未
}
查询图书信息:按名字查询图书 (Java图书管理系统) 按上架日期查询 按种类查询
将图书信息封装成一个类,根据图书对象中保存的信息进行组装sql语句
如:语句初始化为select * from 图书 where 1=1
组装语句
用一个集合(如:columns)保存要用到的字段名
if(null!=书名){
sql语句append( and 书名=? );
集合.add("书名");
}
if(id0){
append( and id=? );
add("id");
}
if(null!=上架日期){
append( and 上架日期=?);
add("上架日期");
}
遍历集合(columns)
for(int i=0;icolumns.size();i++){
setXX(i+1,对象.getXX());
}
//再执行就o了
用java编写一个简单的图书管理系统。 要求:实现浏览,借书,还书,查询,退出等功能(每次最多能借
您好,这个功能要实现并不难,如果您还是学生,应该用的技术都是基础技术来实现对吧。如果是,那么给你一些提示,所使用的技术如,数组或集合,对象,相关变量属性,循环,swatch选择 循环等等。
思路:浏览图示其实就是读取图书的列表或者读取某一本图书的详情。
借书:从图书列表中将对应的书籍数量减掉一定数量。比如 num--;
还书:同借书一样,相加即可;
查询,就是根据书名或者相关信息来查询书库中的图书,一般从数据库获取到这些数据,如果更简单,那就是从集合里面查询。
退出,那就更简单了,exit。
我不清楚你是要使用JavaWeb来实现还是使用C/S架构来实现,还是使用控制台来实现。但是大概的思路都一致。但是复杂度不一样,看你做到什么样的效果和水平。
java中图书查询的功能的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java中图书查询的功能是什么、java中图书查询的功能的信息别忘了在本站进行查找喔。
发布于:2022-11-30,除非注明,否则均为
原创文章,转载请注明出处。