java图书租赁系统代码 java程序设计图书管理系统源码
用java编写一个 图书馆图书借阅管理系统
---------------------------------------------------
创新互联公司是一家专业提供宁化企业网站建设,专注与网站建设、成都做网站、HTML5、小程序制作等业务。10年已为宁化众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
给你修改了三个地方:
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图书馆系统怎么看代码看数据库的信息
点击电脑的开始。
首先点击电脑的开始,找到QLServer配置管理器,将SQLServer网络配置中的SQLEXPRESS的协议如下图中的三个服务改为启用,然后点击TCPIP协议,修改动态端口为1433,重启服务器才能生效,首先建立一个java项目,命名为TestDB然后右键点击TestDB选择buildpath然后找到AddExternalJARs,找到下载的sqljdbc的包,打开即可,然后项目的referencedlibraries目录下能看到导入的包,新建一个包database包中再建立TestConect执行以下代码,代码执行结果和数据库中查询的结果一样。
用java编写一个简单的图书管理系统。 要求:实现浏览,借书,还书,查询,退出等功能(每次最多能借
您好,这个功能要实现并不难,如果您还是学生,应该用的技术都是基础技术来实现对吧。如果是,那么给你一些提示,所使用的技术如,数组或集合,对象,相关变量属性,循环,swatch选择 循环等等。
思路:浏览图示其实就是读取图书的列表或者读取某一本图书的详情。
借书:从图书列表中将对应的书籍数量减掉一定数量。比如 num--;
还书:同借书一样,相加即可;
查询,就是根据书名或者相关信息来查询书库中的图书,一般从数据库获取到这些数据,如果更简单,那就是从集合里面查询。
退出,那就更简单了,exit。
我不清楚你是要使用JavaWeb来实现还是使用C/S架构来实现,还是使用控制台来实现。但是大概的思路都一致。但是复杂度不一样,看你做到什么样的效果和水平。
Java编写图书管理系统,使用XML存储
import java.io.File;
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图书租赁系统代码 java程序设计图书管理系统源码
链接地址:http://pwwzsj.com/article/doijiph.html