包含教室借阅系统java代码的词条
Java编写图书管理系统,使用XML存储
import java.io.File;
成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、做网站、双江网络推广、微信平台小程序开发、双江网络营销、双江企业策划、双江品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联为所有大学生创业者提供双江建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
public class Book {
private int no;
private String name;
private double value;
public Book() {
}
public Book(int no, String name, double value) {
this.no = no;
this.name = name;
this.value = value;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
}
class BookList {
private ListBook bookList;
public BookList() {
bookList = readXML();
}
public long getCount() {
return bookList.size();
}
public ListBook getBookList() {
return bookList;
}
public void setBookList(ListBook bookList) {
this.bookList = bookList;
}
public void add(Book book) {
bookList.add(book);
}
public boolean delete(String name) {
Book book = query(name);
return bookList.remove(book);
}
public void update(Book bookBefore, Book bookAfter) {
bookList.remove(bookBefore);
add(bookAfter);
}
public Book query(String name) {
Book temp = null;
for (Book book : bookList) {
if (book.getName().equals(name)) {
temp = book;
}
}
return temp;
}
public synchronized void writeXmlDocument(Book book) {
try {
File file = new File("D:\\book.xml");
Document document = null;
Element root = null;
if (!file.exists()) {
// 新建student.xml文件并新增内容
document = DocumentHelper.createDocument();
root = document.addElement("Books");//添加根节点
} else {
SAXReader saxReader = new SAXReader();
document = saxReader.read(file);
root = document.getRootElement();//获得根节点
}
Element secondRoot = root.addElement("Book");//二级节点
//为二级节点添加属性,属性值为对应属性的值
secondRoot.addElement("no").setText(book.getNo() + "");
secondRoot.addElement("name").setText(book.getName() + "");
secondRoot.addElement("value").setText(book.getValue() + "");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("GBK");
XMLWriter writer = new XMLWriter(new FileOutputStream("D:\\book.xml"), format);
writer.write(document);
writer.close();
document.clearContent();
} catch (Exception e) {
e.printStackTrace();
}
}
public synchronized ListBook readXML() {
ListBook list = new ArrayListBook();//创建list集合
File file = null;
try {
file = new File("D:\\book.xml");//读取文件
if (file.exists()) {
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(file);
List nodeList = document.selectNodes("Books/Book");
for (int i = 0; i nodeList.size(); i++) {
Element el = (Element) nodeList.get(i);
Book book = new Book();
book.setNo(Integer.parseInt(el.elementText("no")));
book.setName(el.elementText("name"));
book.setValue(Double.parseDouble(el.elementText("value")));
list.add(book);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
class Test {
public static void main(String args[]) {
BookList bl = new BookList();
boolean bBreak = true;
while (bBreak) {
System.out.println("请输入操作代码:");
System.out.println("1:添加 2:删除 3:修改 4:查询 5:书籍统计 6:退出");
Scanner sc = new Scanner(System.in);
int code = sc.nextInt();
if (code == 1) {
System.out.println("请输入编号");
int no = sc.nextInt();
System.out.println("请输入书名");
String name = sc.next();
System.out.println("请输入售价");
double value = sc.nextDouble();
Book book = new Book(no, name, value);
bl.add(book);
bl.writeXmlDocument(book);
} else if (code == 2) {
System.out.println("请输入要删除的书籍名");
String name = sc.next();
if (bl.delete(name)) {
System.out.println("删除成功");
} else {
System.out.println("书籍不存在");
}
} else if (code == 3) {
System.out.println("请输入要修改的书籍名");
String name = sc.next();
Book bookBefore = bl.query(name);
System.out.println("请输入新的编号");
int newNo = sc.nextInt();
System.out.println("请输入新的书名");
String newName = sc.next();
System.out.println("请输入新的售价");
double value = sc.nextDouble();
Book bookAfter = new Book(newNo, newName, value);
bl.update(bookBefore, bookAfter);
} else if (code == 4) {
System.out.println("请输入要查询的书籍名");
String name = sc.next();
Book book = bl.query(name);
System.out.println("编号:" + book.getNo() + " 书名:" + book.getName() + " 售价:" + book.getValue());
} else if (code == 5) {
ListBook list = bl.getBookList();
System.out.println("总书籍数:" + bl.getCount());
for (Book book : list) {
System.out.println("编号:" + book.getNo() + " 书名:" + book.getName() + " 售价:" + book.getValue());
}
} else if (code == 6) {
bBreak = false;
}
}
}
}
jar 包 dom4j.jar jaxen-1.1.4.jar
JAVA对图书馆借阅书籍情况编程
首先这个问题涉及到三个对象和一个动作,即图书对象,学生对象和借书信息的对象,和完成“借书”的动作,图书对象又可以包含图书编号,书名,作者,出版社,出版日期等等,学生对象包含学生编号,姓名,性别,班级,系别等等。借书信息对象包含图书编号,学生编号,借书时间,借书数目等等
写好这三个类,然后分别new一个图书和学生的对象实例,
接着写一个借书动作过程的方法,将图书对象和学生对象的属性保存到借书信息的对象中....代码略
求java编程源代码,关于图书借阅系统的,
eess:跪求运用java实现图书借阅系统的设计源代码
为获取帮助,你需要告诉我们合法的电子邮件地址*
您还能借助baiduhi联系我们或qq:六伍柒幺伍六幺伍
('幺'读
yao
一声)
针对本题目
我们能提供一套与需求相匹配的源代码
es:\bd451e98b28557d0a0ef65c37d6877a8
eess:跪求运用java实现图书借阅系统的设计源代码
交易提醒:预付订金是陷阱
图书馆借阅系统源代码
#includestdio.h #includestring.h #includeconio.h #includestdlib.h #includectype.h #define STACK_INIT_SIZE 10 #define OK 1 #define TRUE 1 #define FALSE 0 #define ERROR 0 struct student /*定义学生类型,用于存放借出的书籍*/ { int carnum; char lendbook[10]; }student[1000]; struct employ /*定义职工类型*/ { int employnum; char employname[15]; int employage; char employsex[2]; char employleve[10]; long int employtage; }employ[50]; struct book /*定义书的类型*/ { int booknum; char bookname[10]; char bookcreat[10]; int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/ }book[1000]; struct car /*借书卡的数据类型*/ { int carnum; char studentname[10]; int studentclass; }car[100]; huanbook() /*还书函数*/ { FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/ int i,n; int carnum; char lendbook[10]; printf("请你输入你的卡号\n"); scanf("%d",carnum); fp=fopen("car.txt","r"); /*读取卡号记录*/ for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/ { if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/ { n=i; fclose(fp); printf("请输入你要还的书的名字\n"); scanf("%s",lendbook); fp=fopen("record.txt","r"); for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/ { if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/ { fclose(fp); fp=fopen("record.txt","r"); fp2=fopen("bookl.txt","w"); for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) { if(strcmp(student[i].lendbook,lendbook)==0) { continue; /*删除还掉的书的借书记录*/ } fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/ } fclose(fp); fclose(fp2); fp=fopen("record.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++) { fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/ } fclose(fp); fclose(fp2); fopen("bookl.txt","w"); /*清临时文件的记录*/ fclose(fp2); fp=fopen("book.txt","r"); fp2=fopen("bookl.txt","w"); for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/ { if(i==n) { book[i].turefalse=1; fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/ continue; } fwrite(book[i],sizeof(struct book),1,fp2); } fclose(fp); fclose(fp2); fp=fopen("book.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++) { fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/ } fclose(fp); fclose(fp2); fopen("bookl.txt","w"); /*清临时文件*/ fclose(fp2); printf("还书完毕,按任意键返回\n"); getch(); return 1; } } printf("你没有借这样的书,任意键返回\n"); /*出错提示*/ fclose(fp); getch(); return 0; } } printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/ fclose(fp); getch(); } findbook() { FILE *fp; char bookname[10]; int ture,i; fp=fopen("book.txt","r"); printf("请输入你要查找的书名\n"); scanf("%s",bookname); for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(bookname,book[i].bookname)==0) { if(book[i].turefalse==1) { printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat); } else {printf("这本书已经有人借出\n");fclose(fp);return 0;} fclose(fp); return FALSE; } } printf("没有你要查询的书籍\n"); fclose(fp); return FALSE; } findbook1() { FILE *fp; char bookcreat[10]; int ture,i; fp=fopen("book.txt","r"); printf("请输入你要查找的作者名\n"); scanf("%s",bookcreat); for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(bookcreat,book[i].bookcreat)==0) { if(book[i].turefalse==1) { printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat); } else {printf("这本书已经有人借出\n");fclose(fp);return 0;} fclose(fp); return FALSE; } } printf("没有你要查询的书籍\n"); fclose(fp); return FALSE; } lendcount() { FILE *fp; int i,n=0; fp=fopen("record.txt","r"); for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) { printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook); n=n+1; } fclose(fp); printf("目前共有%d本书借出\n",n); printf("按任意键\n"); getch(); return n; } chabook() { char ch5; do { printf("---------------欢迎进入图书查询系统!--------------\n"); printf(" 1:按书名查找\n"); printf(" 2:按作者查找\n"); printf(" 0:返回\n"); printf("请输入0--2,其他输入非法!\n"); scanf("%s",ch5); switch(ch5) { case '1':findbook();getch();break; case '2':findbook1();getch();break; case '0':break; default:printf("无此操作\n");getch();break; } }while(ch5!='0'); return FALSE; } lendbook() { FILE *fp,*fp2; int i,n; int carnum; printf("请你输入你的卡号\n"); scanf("%d",carnum); fp=fopen("car.txt","r"); for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) { if(car[i].carnum==carnum) { n=i; fclose(fp); printf("请输入你要借阅的书的名字\n"); scanf("%s",student[n].lendbook); fp=fopen("book.txt","r"); for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(book[i].bookname,student[n].lendbook)==0) { if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;} else fclose(fp); fp=fopen("record.txt","a+"); student[n].carnum=carnum; fwrite(student[n],sizeof(struct student),1,fp); fclose(fp); fp=fopen("book.txt","r"); fp2=fopen("bookl.txt","w"); for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(book[i].bookname,student[n].lendbook)==0) { book[i].turefalse=0; fwrite(book[i],sizeof(struct book),1,fp2); continue; } fwrite(book[i],sizeof(struct book),1,fp2); } fclose(fp); fclose(fp2); fp=fopen("book.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++) { fwrite(book[i],sizeof(struct book),1,fp); } fclose(fp); fclose(fp2); fopen("bookl.txt","w"); fclose(fp2); printf("借书完毕,按任意键返回\n"); getch(); return; } } printf("不存在这样的书,任意键返回\n"); fclose(fp); getch(); return; } } printf("你的卡号不存在,请申请新卡,按任意键返回\n"); fclose(fp); getch(); } carcount() { FILE *fp; int i,n=0; fp=fopen("car.txt","r"); for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) { printf("第%d张卡卡号:%d 姓名:%s 班级:%d\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass); n=n+1; } fclose(fp); printf("目前共有%d本书\n",n); printf("按任意键\n"); getch(); } delcar() { FILE *fp,*fp2; int i; int carnum; char choice; fp=fopen("car.txt","r"); fp2=fopen("bookl.txt","w"); printf("请输入你要删除的卡号\n"); printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n"); scanf("%d",carnum); for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) { if(car[i].carnum!=carnum) { fwrite(car[i],sizeof(struct car),1,fp2); } } fclose(fp); fclose(fp2); printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n"); scanf("%s",choice); if(choice=='y'||choice=='Y') { fp=fopen("car.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(car[i],sizeof(struct car),1,fp2)!=0;i++) { fwrite(car[i],sizeof(struct car),1,fp); } fclose(fp); fclose(fp2); fp2=fopen("bookl.txt","w"); fclose(fp2); printf("按任意键返回\n"); getch(); return; } else { printf("按任意键返回\n"); getch(); return; } } addcar() { FILE *fp; int i=0; fp=fopen("car.txt","a+"); printf("请你输入卡号\n"); scanf("%d",car[i].carnum); printf("请你输入学生姓名\n"); scanf("%s",car[i].studentname); printf("请你输入班级\n"); scanf("%d",car[i].studentclass); fwrite(car[i],sizeof(struct car),1,fp); fclose(fp); printf("输入完毕,任意键返回\n"); getch(); }
用java编写一个 图书馆图书借阅管理系统
---------------------------------------------------
给你修改了三个地方:
1.borrowBooks方法中,将System.out.println("你要借吗?"); 改为:
System.out.println("你要借吗?输入1表示借,其他数字表示不借。");
保证输入的时候输入的数字,否则会报出异常。
2.borrowBooks方法中,将self[score] = all[9]; 改为:self[score] = all[i];
如果是all[9],那么就始终是最后一本书籍信息了。
3.have方法中,你是想将所借的书籍信息都打印出来。修改的比较多,下面注释代码是原来的。
void have(Books[] self) {
// for (int i = 0; i 2; i++) {
// self[i].showBookInfo();
// }
for (int i = 0; i 3; i++) {
if(self[i]!=null)
self[i].showBookInfo();
}
}
****************** 附上所有代码:*************************
import java.util.Scanner;
public class TestBook {
public static void main(String[] args) {
Books all[] = new Books[10];
Books self[] = new Books[3];
all[0] = new Books("java", 1, "12345", "tom", 34.0f, "人民出版社");
all[1] = new Books("c", 2, "12346", "tnn", 31.0f, "人民出版社");
all[2] = new Books("c++", 3, "12445", "mm", 35.0f, "人民出版社");
all[3] = new Books("c#", 4, "12365", "tt", 38.0f, "人民出版社");
all[4] = new Books("j2se", 5, "13345", "tosm", 31.1f, "人民出版社");
all[5] = new Books("j2ee", 6, "18345", "ttm", 32.0f, "人民出版社");
all[6] = new Books("jsp", 7, "12335", "cc", 33.0f, "人民出版社");
all[7] = new Books("net", 8, "12341", "bb", 36.0f, "人民出版社");
all[8] = new Books("ip", 9, "12343", "aa", 37.0f, "人民出版社");
all[9] = new Books("tcp", 10, "22345", "jj", 39.0f, "人民出版社");
Readers r = new Readers("xiaoming", 101, "1", 3);
r.searchAllBooks(all);
r.borrowBooks(all, self);
r.have(self);
r.give(all, self);
}
}
class Readers {
Scanner scan = new Scanner(System.in);
String names;
int nums;
String classes;
int grade;
int score = 0;
// Books self[]=new Books[3];
Readers(String n, int u, String c, int g) {
names = n;
nums = u;
classes = c;
grade = g;
}
void searchAllBooks(Books[] all) {// 查书
for (int i = 0; i 10; i++)
all[i].showBookInfo();
// self[score]=all[0];
}
void give(Books[] all, Books[] self) {// 还书
System.out.println("请输入您要还的书的书号");
int n = scan.nextInt();
for (int i = 0; i 10; i++) {
if (n == all[i].num) {
for (int j = 0; j 3; j++) {
if (self[j] == all[i]) {
self[j] = null;
System.out.println("还书成功");
}
}
}
}
}
void have(Books[] self) {
// for (int i = 0; i 2; i++) {
// self[i].showBookInfo();
// }
for (int i = 0; i 3; i++) {
if(self[i]!=null)
self[i].showBookInfo();
}
}
void giveMoney() {
}
void borrowBooks(Books[] all, Books[] self) {
System.out.println("请输入您要查找的书名:");
String n = scan.next();
int i;
for (i = 0; i 10; i++) {
if (n.equals(all[i].name)) {
all[i].showBookInfo();
break;
}
}
//System.out.println("你要借吗?");
System.out.println("你要借吗?输入1表示借,其他数字表示不借。");
int j;
j = scan.nextInt();
if (j == 1) {
System.out.println("借阅成功");
//self[score] = all[9];
self[score] = all[i];
score += 1;
}
if (score 4) {
System.out.println("您还可以借阅" + (3 - score) + "本");
} else {
System.out.println("对不起,一个人只能借3本");
}
}
}
class Books {
String name;
int num;
String ISBN;
String writer;
float price;
String publisher;
Books(String n, int u, String i, String w, float p, String l) {
name = n;
num = u;
ISBN = i;
writer = w;
price = p;
publisher = l;
}
void showBookInfo() {
System.out.println("**************************");
System.out.println("书名:" + name);
System.out.println("索书号:" + num);
System.out.println("ISBN号:" + ISBN);
System.out.println("价格:" + price);
System.out.println("出版社:" + publisher);
System.out.println("**************************");
}
}
----------------------------------------------------
文章标题:包含教室借阅系统java代码的词条
文章源于:http://myzitong.com/article/hosjih.html