当前位置:首页 » 操作系统 » java图书管理系统源码

java图书管理系统源码

发布时间: 2023-08-20 15:01:41

1. java图书租赁系统源代码

程序如下:
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LibrarySystem
{
static List<String> list = new ArrayList<String>();
static double money = 0;
static boolean borrow = true;
public static void doBorrow()
{
System.out.print("请输入图书名称<计算机书,新书>:");
Scanner scanner = new Scanner(System.in);
String bookName = scanner.next();
System.out.print("请输入图书类型<1:计算机书,2:新书>:");
int type = 0;
int day = 0;
try
{
type = scanner.nextInt();

if((bookName.equals("计算机书") && type != 1) ||
(bookName.equals("新书") && type != 2))
{
System.out.println("类型输入有误,系统退出。");
System.exit(0);
}

} catch (RuntimeException e)
{
System.out.println("类型输入有误,系统退出。");
System.exit(0);
}
System.out.print("请输入借阅天数(必须是整数):");
try
{
day = scanner.nextInt();
} catch (RuntimeException e)
{
System.out.println("天数输入有误,系统退出。");
System.exit(0);
}
double tempMoney = 0;
//计算租金
if(type == 1)
{
tempMoney = day*1.5;
money += tempMoney;
}
else if(type == 2)
{
tempMoney = day > 3?((day-3)*2+4.5):day*1.5;
money += tempMoney;
}

list.add(MessageFormat.format("书名:{0},借阅天数:{1},租金:{2}", bookName,day,tempMoney));
System.out.print("是否继续借书(1-是,2-不是):");
try
{
type = scanner.nextInt();
while(type != 1 && type != 2)
{
System.out.print("输入有误,请重新输入:");
type = scanner.nextInt();
}

borrow = type == 1? true:false;
} catch (RuntimeException e)
{
System.out.println("天数输入有误,系统退出。");
}
}

public static void main(String[] args)
{
System.out.println("============欢迎使用图书租赁管理系统===========");
while(borrow)
{
doBorrow();
}
System.out.println("你的借书记录:");
System.out.println("-----------------------------------");
for(String s : list)
{
System.out.println(s);
}
System.out.println("-----------------------------------");
System.out.println("总金额:" + money);
}
}

有问题欢迎提问,满意请采纳,谢谢!

2. java图书管理系统代码

最近好多人要这份源码啊感觉..有建表脚本..使用mysql数据库..建表之后就可以直接运行了.

3. 采用JAVA设计一个小型图书管理程序(只要增删查改)

使用java语言设计一款小型图书管理系统,能够通过主界面根据关键字查询图书信息,能够添加图书信息和删除过去图书信息

4. 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;i<h;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;i<h;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;i<M;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;i<M;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;i<M;i++)
{k=i;
for(j=i+1;j<M;j++)
if(go[k].price>go[j].price)k=j;
t=go[i];go[i]=go[k];go[k]=t;
}
print();
for(i=0;i<M;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;flag&&i<M;i++)
{if(strcmp(name,go[i].name)==0)
{for(j=i;j<M-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;i<M;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();}
}

5. 求一个java图书管理系统代码,不需要图形化,命令行就可以,只要求实现导入图书,查询,删除

importjava.io.BufferedReader;
importjava.io.File;
importjava.io.FileReader;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Scanner;

publicclassBookWork{

staticList<Book>data;
privatestaticScannerinput;

publicstaticvoidmain(String[]args){
if(!initBook("d:/book.txt")){
System.out.println("初始图书列表失败..");
return;
}
input=newScanner(System.in);
while(true){
try{
System.out.println("请输入操作:");
System.out.println("1.找书2.删除图书3.退出");
intnumber=Integer.parseInt(input.next());
if(number==1){
findBook();
}elseif(number==2){
delBook();
}elseif(number==3){
System.out.println("退出");
break;
}else{
System.out.println("这个不是我要的...重来...");
System.out.println();
}

}catch(Exceptione){
e.printStackTrace();
System.out.println("这个不是我要的...重来...");
System.out.println();
}
}
}

privatestaticvoiddelBook(){
System.out.println("请输入要删除的书名或编号:");
Stringkey=input.next();
if(key!=null&&!key.equals("")){

for(Bookbook:data){
if(book.number.equals(key)||book.name.contains(key)){
data.remove(book);
System.out.println("图书"+book.toString()+"已删除");
return;
}
}
}
System.out.println("没有您要删除的");

}

privatestaticvoidfindBook(){
System.out.println("请输入要查找的书名或编号:");
Stringkey=input.next();
if(key!=null&&!key.equals("")){

for(Bookbook:data){
if(book.number.equals(key)||book.name.contains(key)){
System.out.println("找到了图书"+book.toString());
return;
}
}
}
System.out.println("没有您要找的");
}

privatestaticbooleaninitBook(Stringstring){
try{
System.out.println("图书导入中...");
System.out.println("列表文件--"+string);

Filefile=newFile(string);
if(!file.exists()){
returnfalse;
}
data=newArrayList<Book>();
BufferedReaderbufferedReader=newBufferedReader(newFileReader(file));
Stringline="";
while((line=bufferedReader.readLine())!=null){
String[]strings=line.split(",");
Bookb=newBook(strings[0],strings[1]);
data.add(b);
System.out.println("导入"+b.toString());
}
}catch(Exceptione){
e.printStackTrace();
returnfalse;
}
returntrue;
}

publicstaticclassBook{
Stringnumber;
Stringname;

publicBook(Stringnumber,Stringname){
super();
this.number=number;
this.name=name;
}

@Override
publicStringtoString(){
return"Book[编码:"+number+",名称:"+name+"]";
}
}
}

001,金瓶梅

002,杂事秘辛

003,飞燕外传

004,控鹤监秘记

005,汉宫春色

热点内容
安卓文档文件夹在哪里 发布:2025-03-09 21:50:59 浏览:226
mysql的建的数据库在哪 发布:2025-03-09 21:48:34 浏览:135
怎么打开服务器80端口 发布:2025-03-09 21:48:33 浏览:213
pdb如何配置dns 发布:2025-03-09 21:47:00 浏览:937
网吧卡号和密码怎么填 发布:2025-03-09 21:46:28 浏览:744
我的世界最火的服务器国际版电脑 发布:2025-03-09 21:45:32 浏览:792
手机游戏脚本大全 发布:2025-03-09 21:43:26 浏览:778
java中的hashcode 发布:2025-03-09 21:42:30 浏览:856
php弹窗代码 发布:2025-03-09 21:40:26 浏览:284
阿里云gpu服务器价格 发布:2025-03-09 21:39:18 浏览:178