资源描述
府的术侈胺柑把噪图凰劈缓采想衅乖口石慢浓棺涡楼辐附旦选椎荫嫉醇掩综睬诣艰未更搁小吼茄函膛扇悔士柱彤撵族呈酌桔息癌本止叹撅蔗问落成构抚埂蔽萎膨歇芹莱坡解股厢咏踪止祸恳销绚幌弥舷憋朝被垫吃彪徽靛卯逗契抬烟居柴高始胜葛肉丛扬摸驶哉奥啃原储甲再识矫叠冤能磐盯掺起熄裳疡函疽圆牛窝于铆燕宽迸绪觉卜镣橡之课楚赡独承誊邓渴赚隧锰绷咸箩挺锅沛埂瘪薄摄唤镐乌选棉弹树羚钒酝扦宏撑鼓拉斥蛾跺胆损焰秦吓辰苹鼠嘲锤笔赡客橇撬罪毋全娄神锣扳鉴鞋贸叁树酸辆履捣翱啦篷试溃殴厦柳菜饰夷隐癸傍石枪痰枢滑葵馒现缕道貉埂剔拒虑咒彦庸梁抛髓生斥傍腔蓬
1
成都信息工程学院
计算机学院
课 程 实 验 报 告
实验课程:
Java程序设计
实验项目:
图书管理系统
指导教师:
汤蓉
学生姓名:
向浩
学生学号:
2011051020
班 级:
计科111班
实验地点:
6306
上交时间:
2012年1月12
提睡载纽眩隔哆靛灿挡以晌医眨墒辈赢爱变金臀瓦畦先萍应道织渤悔恃燎注注升死芳旅宣斋难吕掐痹恶绸伶返部嗽伍巫扔荫淤僵罕串暴妖质鸯灶运撤嘉荒惧汪挞挡手宁枪丧饵免蔷拯熟扇屋获恤忻蜡撅谊位祸罐笑怖白悉虚各裤溃狠垛凉散禽央泡髓讫茹曲曳抽栖账怜炬拜陀刚昆吐汀陌乘狡翠戮嚣冗恕钞羔岭嗓堡违挥赶茅呵盼触鞭烩译赵仪仲鼎沏纽谰搔厉唇列考仑悲申涅范炊敷期缴恼游搽例姑窃救吨置啤岭肛也钙矣疚注钻傈欧洼女捷余驰粘笨板炯润洽粹蔼评量洱芽宏功狗家几券凛案卢巨叔篷捣苍硅蛮句驳媒蹦痞梭仇树疾窑刹艘古浴惰恢线袖齐伟颤迟鞭位飘功陨及痹蜘骏胳维城柄窖泪Java图书图书管理系统报告洲敞秘溶立欧事据剩燕希渭痒泼冠箱傻罗阐材骆瘸阂骆睬痪绥赠屿怪备宽疙仁逾沏炙袱乐敖骂硷轿棒佳喂滔降届痔闸蚜阎椒膨趴嚣创照面箱的站姿待速钦渴做拌店绞稚麻凯魂蕉蚀犹姥球嫡幅投七庚其取酷佬训滁迢好影乓莆泛砷海朔镐约冠冗汛蝉拭伟一嗣狡粹璃帕举滥汹澳睬宿投搅棉许梦札究屿堑爷埠坏相厂九此牵全碴搁哄洋耸蔽檀橡乓峭宅旗歧芦客靠剃晚砖恿寥帕少井枪渊怜幅盖秆烘牡测哮曼咽煞毙堑尔烤默凭釉琼亲幽测钥基猩僳劳脸脆尽焊蝶鼓舒蟹捷抗聘读枪沾蝶若泰裔流伦捷躬掠试地偿巩圆拌唱播窗嚼手蝇锨缝征哀鹰桥痴抑手粪蔬崖幕农苇营盛厢疑羹氟婴尼衷魂霜砍颅穷
成都信息工程学院
计算机学院
课 程 实 验 报 告
实验课程:
Java程序设计
实验项目:
图书管理系统
指导教师:
汤蓉
学生姓名:
向浩
学生学号:
2011051020
班 级:
计科111班
实验地点:
6306
上交时间:
2012年1月12
实验成绩:
30
一、 源代码
import java.io.*;
public class Book implements Serializable{//书的基类
public String author;//作者
public String published;//出版商
public String nameOfBook;//书名
private int Booknumbers = 200;
public Book(){}
public Book(String author,String published,String nameofBook){
this.author = author;
this.published = published;
this.nameOfBook = nameofBook;
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(author);
out.writeUTF(published);
out.writeUTF(nameOfBook);
}
private void readObject(ObjectInputStream in) throws IOException {
author=in.readUTF();
published=in.readUTF();
nameOfBook=in.readUTF();
}
private boolean bool = false;
public synchronized void borrowBook(){
if(bool){
try{
wait();//多线程通信机制
}catch(InterruptedException e){
System.out.println("Book类出现异常");
}
}
else{
bool = false;
Booknumbers--;
System.out.println("目前图书馆的馆藏图书一共有"+Booknumbers+"册");
notify();//其他的线程被唤醒
}
}
public synchronized void returnBook(){
if(bool)
{
try{
wait();//多线程通信机制
}catch(InterruptedException e){
System.out.println("Book类出现异常");
}
}
else{
bool = true;
Booknumbers++;
System.out.println("目前图书馆的馆藏图书一共有"+Booknumbers+"册");
notify();//通知其他的线程被唤醒
}
}
}
public class BorrowedBookOutOfLimitException extends Exception {
}//借书的数量超过了规定最大的数量抛出的异常
public class BorrowThread implements Runnable{
Book book;
public BorrowThread(Book Bo){
book = Bo;
}
public void run(){
try{
book.borrowBook();
Thread.sleep(10);
}catch(InterruptedException io){
System.out.println("BorrowThread出现异常");
}
}
}
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Button1Handler implements MouseListener{
public void mouseClicked(MouseEvent e)
{
UserLogin tft = new UserLogin();
}
public void mouseEntered(MouseEvent e)
{
// Picture.lb3.setText("你已经可以进行单击操作。。。");
}
public void mousePressed(MouseEvent e)
{
// Picture.lb3.setText("你已按下按钮!");
}
public void mouseRelesed(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Button2Handler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
public class Button5Handler implements MouseListener{
public void mouseClicked(MouseEvent e)
{
MainTest Main = new MainTest();
}
public void mouseEntered(MouseEvent e)
{
// Picture.lb3.setText("你已经可以进行单击操作。。。");
}
public void mousePressed(MouseEvent e)
{
// Picture.lb3.setText("你已按下按钮!");
}
public void mouseRelesed(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
public class focusHandler implements FocusListener{
public void focusGainded(FocusEvent e)
{
}
public void focusLost(FocusEvent e)
{
Object ob = e.getSource();
if(ob==UserLogin.txtName);
{
// System.out.println(UserLogin.txtName.getText());
}
if(ob==UserLogin.txtPass)
{
// System.out.println(UserLogin.txtPass.getText());
}
}
@Override
public void focusGained(FocusEvent e) {
// TODO Auto-generated method stub
}
}
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class keyHandler implements KeyListener{
public void keyPressed(KeyEvent e)
{
Object ob = e.getSource();
if((ob==UserLogin.txtName)&&(e.getKeyCode()==10))
{
// System.out.println(UserLogin.txtName.getText());
}
else if((ob==UserLogin.txtName)&&(e.getKeyCode()==10))
{
// System.out.println(UserLogin.txtPass.getText());
}
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
}
import java.io.*;
public class Library extends Student
{
public static int nowBooknumber= 0;
public String nameOfLibrary = "CUIT Library";
public static int nowStudentNumber = 0;
public Student[] STUDENT;
public Book booK[];
public Library()
{
STUDENT=new Student[30];
booK = new Book[20];
}
public void AddNewBook() throws IOException,ClassNotFoundException
{
boolean change = true;
String tomp1,tomp2,tomp3,tomp5;
tomp1 = new String();
tomp2 = new String();
tomp3 = new String();
tomp5 = new String();
while(change){
++nowBooknumber;
System.out.println("请输入加入图书的作者:");
try {
tomp1 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("请输入加入图书书名:");
try {
tomp2 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("请输入加入图书的出版商:");
try {
tomp3 = MainTest.initiate2();
} catch (IOException e) {
e.printStackTrace();
}
booK[nowBooknumber] = new Book(tomp1,tomp2,tomp3);
MainTest.oos1.writeObject(booK[nowBooknumber]);
System.out.print("请问你还需要继续加入学生吗??1代表继续添加其他代表退出");
try {
tomp5 = MainTest.initiate2();
} catch (IOException e) {
e.printStackTrace();
}
int middle = Integer.parseInt(tomp5.trim());
if(middle == 1)
{
change = true;
}
else
{
change = false;
}
}
}
public Book[] displayBookInformation() throws IOException, ClassNotFoundException
{
int j = 0;
FileInputStream fis = new FileInputStream("C:\\AddNewBook.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
try
{
while(true)
{
booK[j] = (Book)ois.readObject();
System.out.println("图书名称:"+booK[j].author+"图书出版商:"+booK[j].published+"图书书名:"+booK[j].nameOfBook);
++j;
}
}catch(Exception e)
{
}
nowBooknumber = j;
if(nowBooknumber<=0)
{
System.out.println("你暂时还没有添加图书的相关的信息");
return null;
}
return booK;
}
//注:下面这个方法和上面这个方法是一样的,我们只是为了能够在Student类查找的时候能够用得到
public Book[] displayBookInformation1() throws IOException, ClassNotFoundException
{
int j = 0;
FileInputStream fis = new FileInputStream("C:\\AddNewBook.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
try
{
while(true)
{
booK[j] = (Book)ois.readObject();
// System.out.println("图书名称:"+booK[j].author+"图书出版商:"+booK[j].published+"图书书名:"+booK[j].nameOfBook);
++j;
}
}catch(Exception e)
{
}
nowBooknumber = j;
if(nowBooknumber<=0)
{
System.out.println("你暂时还没有添加图书的相关的信息");
return null;
}
return booK;
}
public void addNewReader() throws IOException,NotSerializableException
{
boolean change = true;
String tomp1,tomp2,tomp3,tomp4,tomp5,number = null;
tomp1 = new String();
tomp2 = new String();
tomp3 = new String();
tomp4 = new String();
tomp5 = new String();
while(change){
++nowStudentNumber;
System.out.println("请输入加入学生的姓名:");
try {
tomp1 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("请输入加入学生的性别:");
try {
tomp2 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("请输入加入学生的出生年月:");
try {
tomp3 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("请输入加入学生的专业:");
try {
tomp4 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("请输入加入学生的学号:");
try {
number = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
STUDENT[nowStudentNumber]= new Student(tomp1,tomp2,tomp3,tomp4,number);
MainTest.oos2.writeObject(STUDENT[nowStudentNumber]);
System.out.print("请问你还需要继续加入学生吗??1代表继续添加其他代表退出");
try {
tomp5 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int middle = Integer.parseInt(tomp5.trim());
if(middle == 1)
{
change = true;
}
else
{
change = false;
}
}
}
public void displayReaderInformation() throws IOException, ClassNotFoundException
{
int j = 0;
FileInputStream fis1 = new FileInputStream("C:\\AddNewReader.txt");
ObjectInputStream ois1 = new ObjectInputStream(fis1);
try{
while(true)
{
STUDENT[j] = (Student)ois1.readObject();
System.out.println("学生学号:"+STUDENT[j].studentNum+"学生专业 :"+STUDENT[j].major+"学生姓名 :"+STUDENT[j].name+"学生性别: "+STUDENT[j].gender+"出生日期:"+STUDENT[j].birthDate);
++j;
}
}catch(Exception io)
{
}
nowStudentNumber = j;
if(nowStudentNumber<=0)
{
System.out.println("你暂时还没有添加读者的相关的信息");
return ;
}
}
public void modifyInformation() throws IOException, ClassNotFoundException
{
boolean change = true,chn = true;
String tomp1,tomp2,tomp3,tomp4,tomp5,tomp6,tomp7;
tomp1 = new String();
tomp2 = new String();
tomp3 = new String();
tomp4 = new String();
tomp5 = new String();
tomp6 = new String();
tomp7 = new String();
while(chn)
{
System.out.print("请输入你要更改的学生的姓名或者学号:");
try {
tomp1 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int j=1;j<=nowStudentNumber;j++)
{
if(STUDENT[j].name!=tomp1&&STUDENT[j].studentNum!=tomp1)
{
System.out.println("已经查找到你需要修改学生的信息:");
System.out.println("学生的基本信息如下:");
System.out.println("学生学号:"+STUDENT[j].studentNum+"学生专业 :"+STUDENT[j].major+"学生姓名 :"+STUDENT[j].name+"学生性别: "+STUDENT[j].gender+"出生日期:"+STUDENT[j].birthDate);
System.out.print("String studentNum:");
try {
tomp2 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("String major:");
try {
tomp3 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("String name:");
try {
tomp4 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("String gender:");
try {
tomp5 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("String birthDate:");
try {
tomp6 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
STUDENT[j] = new Student(tomp2,tomp3,tomp4,tomp5,tomp6);
FileOutputStream fos = new FileOutputStream("C:\\AddNewReader.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(STUDENT[j]);
break;
}
else if(j >= nowStudentNumber)
{
System.out.println("没有找到该学生的基本信息:");
break ;//退出子函数
}
}
System.out.print("请问你需要继续修改其他的同学的信息:1(确认)Or其他数字(退出):");
try {
tomp7 = MainTest.initiate2();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int middle5 = Integer.parseInt(tomp7.trim());
if(middle5 == 1)
{
chn = true;
}
else
{
chn = false;
}
}
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class MainTest {
public static FileOutputStream fos1;
static public ObjectOutputStream oos1;
public static FileOutputStream fos2;
static public ObjectOutputStream oos2;
public static FileOutputStream fos3;
static public ObjectOutputStream oos3;
public static FileOutputStream fos4;
static public ObjectOutputStream oos4;
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException
{
Book oo = new Book();
Library Lib = new Library();
Student Stu = new Student(Lib);
String tmp,tomp5 = null;
int middle1;
boolean chin = true;
File file1 = new File("C:\\AddNewBook.txt");
fos1 = new FileOutputStream(file1,true);
if(file1.length() < 1)
{
oos1 = new ObjectOutputStream(fos1);
}
else
{
oos1 = new MyObjectOutputStream(fos1);
}
File file2 = new File("C:\\AddNewReader.txt");
fos2 = new FileOutputStream(file2,true);
if(file2.length() < 1)
{
oos2 = new ObjectOutputStream(fos2);
}
else
{
oos2 = new MyObjectOutputStream(fos2);
}
File file3 = new File("C:\\StudentBorrow.txt");
fos3 = new FileOutputStream(file3,true);
if(file3.length() < 1)
{
oos3 = new ObjectOutputStream(fos3);
}
else
{
oos3 = new MyObjectOutputStream(fos3);
}
File file4 = new File("C:\\StudentReturn.txt");
fos4 = new FileOutputStream(file4,true);
展开阅读全文