java编写图书借阅代码 图书借阅系统java代码
利用Java实现图书的借阅管理功能,采用文本文件方式存储数据自行设计数据结构。
//只实现了图书的添加
创新互联建站于2013年成立,是专业互联网技术服务公司,拥有项目网站设计制作、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元新城做网站,已为上家服务,为新城各地企业和个人服务,联系电话:028-86922220
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对图书馆借阅书籍情况编程
首先这个问题涉及到三个对象和一个动作,即图书对象,学生对象和借书信息的对象,和完成“借书”的动作,图书对象又可以包含图书编号,书名,作者,出版社,出版日期等等,学生对象包含学生编号,姓名,性别,班级,系别等等。借书信息对象包含图书编号,学生编号,借书时间,借书数目等等
写好这三个类,然后分别new一个图书和学生的对象实例,
接着写一个借书动作过程的方法,将图书对象和学生对象的属性保存到借书信息的对象中....代码略
java设计一个图书借阅程序
package Management;
import java.util.List;
import java.util.ArrayList;
public class Management {
public static ListBook bookList=null;
public Management() {
// TODO Auto-generated constructor stub
bookList=new ArrayListBook(100);
}
public void addbook(Book book)
{
bookList.add(book);
}
public Book[] findBook(String bookName)
{
Book [] book=new Book[100];
int j=0;
for(int i=0;ibookList.size();i++)
{
if(bookName.equals(bookList.get(i).getName()))
{
book[j]=bookList.get(i);
j++;
}
}
return book;
}
public Book[] ShowAllBook()
{
Book[]book=new Book[100];
for(int i=0;ibookList.size();i++)
{
book[i]=bookList.get(i);
bookList.get(i).printInfo();
}
return book;
}
}
class Book
{
private String name;
private String author;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
void printInfo()
{
System.out.println("书名为"+this.name+"作者为"+this.author);
}
}
class Reader
{
private String name;
public void borrowbook(Book book) {
Management liabry=new Management();
for(int i=0;iliabry.bookList.size();i++)
{ if(book.getAuthor().equals(liabry.bookList.get(i).getAuthor())book.getName().equals(liabry.bookList.get(i).getName()))
{
liabry.bookList.remove(i);
System.out.println("借书成功!");
break;
}
}
}
public void backbook(Book book) {
Management liabry=new Management();
liabry.addbook(book);
System.out.println("还书成功");
}
}
本文题目:java编写图书借阅代码 图书借阅系统java代码
转载来于:http://azwzsj.com/article/dohipcd.html