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();
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()+"已删除");
System.out.println("没有您要删除的");
privatestaticvoidfindBook(){
System.out.println("请输入要查找的书名或编号:");
System.out.println("找到了图书"+book.toString());
System.out.println("没有您要找的");
privatestaticbooleaninitBook(Stringstring){
System.out.println("图书导入中...");
System.out.println("列表文件--"+string);
Filefile=newFile(string);
if(!file.exists()){
returnfalse;
data=newArrayListBook();
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());
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,汉宫春色
先考虑软件环境问题,确定好开发工具和数据库。图书馆管理系统,我的理解就是一个档案管理而已,数据库用sql
---------------------------------------------------
给你修改了三个地方:
1.borrowBooks方法中,将System.out.println("你要借吗?");改为:
System.out.println("你要借吗?输入1表示借,其他数字表示不借。");
保证输入的时候输入的数字,否则会报出异常。
2.borrowBooks方法中,将self[score]=all[9];改为:self[score]=all[i];
如果是all[9],那么就始终是最后一本书籍信息了。
3.have方法中,你是想将所借的书籍信息都打印出来。修改的比较多,下面注释代码是原来的。
voidhave(Books[]self){
//for(inti=0;i2;i++){
//self[i].showBookInfo();
//}
for(inti=0;i3;i++){
if(self[i]!=null)
self[i].showBookInfo();
******************附上所有代码:*************************
publicclassTestBook{
Booksall[]=newBooks[10];
Booksself[]=newBooks[3];
all[0]=newBooks("java",1,"12345","tom",34.0f,"人民出版社");
all[1]=newBooks("c",2,"12346","tnn",31.0f,"人民出版社");
all[2]=newBooks("c++",3,"12445","mm",35.0f,"人民出版社");
all[3]=newBooks("c#",4,"12365","tt",38.0f,"人民出版社");
all[4]=newBooks("j2se",5,"13345","tosm",31.1f,"人民出版社");
all[5]=newBooks("j2ee",6,"18345","ttm",32.0f,"人民出版社");
all[6]=newBooks("jsp",7,"12335","cc",33.0f,"人民出版社");
all[7]=newBooks("net",8,"12341","bb",36.0f,"人民出版社");
all[8]=newBooks("ip",9,"12343","aa",37.0f,"人民出版社");
all[9]=newBooks("tcp",10,"22345","jj",39.0f,"人民出版社");
Readersr=newReaders("xiaoming",101,"1",3);
r.searchAllBooks(all);
r.borrowBooks(all,self);
r.have(self);
r.give(all,self);
classReaders{
Scannerscan=newScanner(System.in);
Stringnames;
intnums;
Stringclasses;
intgrade;
intscore=0;
//Booksself[]=newBooks[3];
Readers(Stringn,intu,Stringc,intg){
names=n;
nums=u;
classes=c;
grade=g;
voidsearchAllBooks(Books[]all){//查书
for(inti=0;i10;i++)
all[i].showBookInfo();
//self[score]=all[0];
voidgive(Books[]all,Books[]self){//还书
System.out.println("请输入您要还的书的书号");
intn=scan.nextInt();
for(inti=0;i10;i++){
if(n==all[i].num){
for(intj=0;j3;j++){
if(self[j]==all[i]){
self[j]=null;
System.out.println("还书成功");
voidgiveMoney(){
voidborrowBooks(Books[]all,Books[]self){
System.out.println("请输入您要查找的书名:");
Stringn=scan.next();
inti;
for(i=0;i10;i++){
if(n.equals(all[i].name)){
//System.out.println("你要借吗?");
intj;
j=scan.nextInt();
if(j==1){
System.out.println("借阅成功");
//self[score]=all[9];
self[score]=all[i];
score+=1;
if(score4){
System.out.println("您还可以借阅"+(3-score)+"本");
System.out.println("对不起,一个人只能借3本");
classBooks{
intnum;
StringISBN;
Stringwriter;
floatprice;
Stringpublisher;
Books(Stringn,intu,Stringi,Stringw,floatp,Stringl){
name=n;
num=u;
ISBN=i;
writer=w;
price=p;
publisher=l;
voidshowBookInfo(){
System.out.println("**************************");
System.out.println("书名:"+name);
System.out.println("索书号:"+num);
System.out.println("ISBN号:"+ISBN);
System.out.println("价格:"+price);
System.out.println("出版社:"+publisher);
----------------------------------------------------
最近好多人要这份源码啊感觉..有建表脚本..使用mysql数据库..建表之后就可以直接运行了.