赞
踩
为图书管理人员编写一个图书管理系统,图书管理系统的设计主要是实现对图书的管理和相关操作,包括3个表:
图书信息表——存储图书的基本信息,包括书号、书名、作者、出版社、出版日期、存馆数量、定价等。
读者信息表——存储读者的基本信息,包括学号、姓名、学院、专业班级等。
图书借阅表——存储读者借书的相关信息,包括学号、姓名、书号、书名、借阅日期、应还日期、归还日期等。
- //这是图书
- public class Books implements Serializable {
- private int booknum;
- private String bookname;
- private String writername;
- private String publisher;//出版社
- private String publishtime;//出版社日期
- private int number=0;//馆藏数量
- private int price=0;
-
- public void setNumber(int number) {
- this.number = number;
- }
-
- public void setBooknum(int booknum) {
- this.booknum = booknum;
- }
-
- public void setBookname(String bookname) {
- this.bookname = bookname;
- }
-
- public void setWritername(String writername) {
- this.writername = writername;
- }
-
- public int getBooknum() {
- return booknum;
- }
-
- public String getBookname() {
- return bookname;
- }
-
- public String getWritername() {
- return writername;
- }
-
- public String getPublisher() {
- return publisher;
- }
-
- public String getPublishtime() {
- return publishtime;
- }
-
- public int getNumber() {
- return number;
- }
-
- public int getPrice() {
- return price;
- }
-
- public Books(int booknum,String bookname, String writername, String publisher
- , String publishtime, int number, int price){
- this.bookname=bookname;
- this.number=number;
- this.price=price;
- this.publisher=publisher;
- this.publishtime=publishtime;
- this.writername=writername;
- this.booknum=booknum;
- }
-
- @Override
- public String toString() {
- return "Books{" +
- "booknum=" + booknum +
- ", bookname='" + bookname + '\'' +
- ", writername='" + writername + '\'' +
- ", publisher='" + publisher + '\'' +
- ", publishtime='" + publishtime + '\'' +
- ", number=" + number +
- ", price=" + price +
- '}';
- }
-
- boolean equalsTwo(Books book){
- if((this.bookname.equals(book.getBookname())&&this.publishtime.equals(book.getPublishtime())&&this.writername.equals(book.getWritername())
- &&this.publisher.equals(book.getPublisher())&&this.getBooknum()==book.getBooknum()&&this.price==book.price)||this.getBooknum()==book.getBooknum()
- ){
- return true;
- }
- return false;
- }
- }
-
-
- public class readman implements Serializable {
- private long number;//学号
- private String name;//姓名
- private String college;//学院
- private String majorclass;//专业班级
-
- public readman(long number, String name, String college, String majorclass) {
- this.number = number;
- this.name = name;
- this.college = college;
- this.majorclass = majorclass;
- }
-
- public void setNumber(long number) {
- this.number = number;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setCollege(String college) {
- this.college = college;
- }
-
- public void setMajorclass(String majorclass) {
- this.majorclass = majorclass;
- }
-
- public long getNumber() {
- return number;
- }
-
- public String getName() {
- return name;
- }
-
- public String getCollege() {
- return college;
- }
-
- public String getMajorclass() {
- return majorclass;
- }
-
- @Override
- public String toString() {
- return "readman{" +
- "number=" + number +
- ", name='" + name + '\'' +
- ", college='" + college + '\'' +
- ", majorclass='" + majorclass + '\'' +
- '}';
- }
- public boolean equalsT(readman r){
- if((this.college.equals(r.college)&&this.majorclass.equals(r.majorclass)&&
- this.name.equals(r.name)&& this.number==r.number)||
- this.number==r.number
- ){
- return true;
- }
- return false;
- }
- }
- //借阅
-
- public class BookBorrow implements Serializable {
- private String manname;//读者姓名
- private long mannumber;//读者学号
- private int booknumber;//书号
- private String bookname;//书名
- private String borrowtime;//借阅时间
- private String returntime;//归还时间
-
- public BookBorrow(String manname, long mannumber,
- int booknumber, String bookname,
- String borrowtime, String returntime) {
- this.manname = manname;
- this.mannumber = mannumber;
- this.booknumber = booknumber;
- this.bookname = bookname;
- this.borrowtime = borrowtime;
- this.returntime = returntime;
- }
-
- public boolean equalst(BookBorrow b){
- if(this.booknumber==b.booknumber&&this.mannumber==b.mannumber){
- return true;
- }
- return false;
- }
- @Override
- public String toString() {
- return "BookBorrow{" +
- "manname='" + manname + '\'' +
- ", mannumber=" + mannumber +
- ", booknumber=" + booknumber +
- ", bookname='" + bookname + '\'' +
- ", borrowtime='" + borrowtime + '\'' +
- ", returntime='" + returntime + '\'' +
- '}';
- }
-
- public String getManname() {
- return manname;
- }
-
- public long getMannumber() {
- return mannumber;
- }
-
- public int getBooknumber() {
- return booknumber;
- }
-
- public String getBookname() {
- return bookname;
- }
-
- public String getBorrowtime() {
- return borrowtime;
- }
-
- public String getReturntime() {
- return returntime;
- }
-
- public void setManname(String manname) {
- this.manname = manname;
- }
-
- public void setMannumber(long mannumber) {
- this.mannumber = mannumber;
- }
-
- public void setBooknumber(int booknumber) {
- this.booknumber = booknumber;
- }
-
- public void setBookname(String bookname) {
- this.bookname = bookname;
- }
-
- public void setBorrowtime(String borrowtime) {
- this.borrowtime = borrowtime;
- }
-
- public void setReturntime(String returntime) {
- this.returntime = returntime;
- }
- }
1.图书信息添加功能:包括书号、书名、作者、出版社、存馆数量、定价等。
2.图书信息查询:分别按书名,按作者名,按出版社等进行查询。
3.图书信息排序:按书号、书名等按升序进行排序。
4.图书信息的修改、删除:按书号或书名进行图书的修改和删除。
5.读者信息添加功能:包括学号、姓名、学院、专业班级等。
6.读者信息查询:分别按学号、姓名、专业班级等进行查询。
7.读者信息排序:按学号、学院等按升序进行排序。
8.读者信息的修改、删除:按学号+姓名进行读者信息的修改和删除。
9.图书借阅:输入学号+书号,如果该书图书信息表中的存馆数量大于0,则可以借出,借出相应数量后修改图书信息表中的存馆数量,在图书借阅表添加该同学的借阅。
10.图书归还:输入学号+书号,修改图书信息表中的存馆数量,在图书借阅表中记录该同学的归还时间。
11.图书借阅查询:分别按学号、书名、学院等进行查询。
12.图书全部展示:
13.退出
- public void menu(){
- while(loop){
- System.out.println("===========图书管理系统============");
- System.out.println("========1.图书信息添加功能=========");
- System.out.println("========2.图书信息查询============");
- System.out.println("========3.图书信息排序============");
- System.out.println("========4.图书信息的修改==========");
- System.out.println("========5.读者信息添加功能=========");
- System.out.println("========6.读者信息查询============");
- System.out.println("========7.读者信息排序============");
- System.out.println("========8.读者信息的修改、删除=====");
- System.out.println("========9.图书借阅===============");
- System.out.println("========10.图书归还==============");
- System.out.println("========11.图书借阅查询===========");
- System.out.println("========12.图书全部展示===========");
- System.out.println("========13.退出===========");
- System.out.println("========请输入序号===========");
- int a=1;
- String ss="1";
- boolean qq=true;
- while(qq){ //这个循环控制是不是输入的数字
- ss=myScanner.next();
- if(panduan(ss)) {
- //panduan是一个我自己定义的函数下面会介绍,功能是判断字符串是不是纯数字
- a=Integer.parseInt(ss);
- qq=false;
- }else {
- System.out.println("重新输入!");
- a=0;
- }}
- if(a!=0){
- switch (a){
- case 1:
- add();
- break;
- case 2:
- if(books.size()!=0){//首先判断books的数量,如果没有书籍的话,不能进入
- outFile();//把books写入文件,后面会介绍
- look();
- }else
- System.out.println("图书馆现在没有书籍!");
- break;
- case 3:
- if(books.size()!=0){
- outFile();
- qsort();
- }else{
- System.out.println("图书馆现在没有书籍!");
- }
- break;
- case 4:
- if(books.size()!=0){
- outFile();
- modify();
- }else{
- System.out.println("图书馆现在没有书籍!");
- }
- break;
- case 5:
- addReadman();
- break;
- case 6:
- if(readmans.size()!=0){//首先判断readmans的数量,如果没有书籍的话,不能进入
- manoutFile();//把readmans写入文件,后面会介绍
- findman();
- }else{
- System.out.println("现在表中没有读者信息!");
- }
- break;
- case 7:
- if(readmans.size()!=0){
- manoutFile();
- mansort();
- }else{
- System.out.println("现在表中没有读者信息!");
- }
- break;
- case 8:
- if(readmans.size()!=0){
- manoutFile();
- manmodify();
- }else{
- System.out.println("现在表中没有读者信息!");
- }
- break;
- case 9:
- if((readmans.size()!=0&&books.size()!=0)||bookBorrows.size()!=0){
- outFile();
- manoutFile();
- bookborrow();
- }else{
- System.out.println("现在表中没有信息!");
- }
- break;
- case 10:
- //首先判断bookBorrows的数量,如果没有书籍的话,不能进入
- if(bookBorrows.size()!=0){
- outFile();//把bookBorrows写入文件,后面会介绍
- manoutFile();
- bookreturn();
- }else{
- System.out.println("现在表中没有信息!");
- }
- break;
- case 11:
- if(bookBorrows.size()!=0){
- fileborrows();
- for (BookBorrow b:bookBorrows){
- System.out.println(b);
- }
- }else{
- System.out.println("现在表中没有信息!");
- }
- break;
- case 12:
- if(books.size()!=0){
- outFile();
- ObjectInputStream obi=null;
- try {
- obi=new ObjectInputStream(newFileInputStream("d:\\books.txt"));
- Vector<Books> books20=(Vector<Books>)obi.readObject();
- for(int i=0;i<books20.size();i++){
- Books book9=books20.get(i);
- System.out.println(book9);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }else {
- System.out.println("图书馆现在没有书籍");
- }
- break;
- case 13:
- loop=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
-
- }
- //三国演义 罗贯中 清华 2001-1-3 10 19
- }else{
- System.out.println("输入错误!重新输入吧!");
- }
-
- }
- System.out.println("已退出图书管理系统!");
- }
- public boolean panduan(String ss){
- for(int i=0;i<ss.length();i++){
- if(!Character.isDigit(ss.charAt(i))){
- return false;
- }
- }
- return true;
- }
- //books的文件操作
- void outFile(){
- try {
- BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("d:\\books.txt",false));
- bufferedWriter.write("");
- bufferedWriter.write("");
- //以上是清空之前的操作,以便于我们重新输入
- } catch (Exception e) {
- e.printStackTrace();
- }
- ObjectOutputStream obo=null;
- try {
- obo=new ObjectOutputStream(new FileOutputStream("d:\\books.txt"));
- obo.writeObject(books);
- } catch (IOException e) {
- e.printStackTrace();
- }finally {
- try {
- obo.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
- }
- //readmans的文件操作
- void manoutFile(){
- try {
- BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("d:\\readmans.txt",false));
- bufferedWriter.write("");
- bufferedWriter.write("");
- //以上是清空之前的操作,以便于我们重新输入
- } catch (Exception e) {
- e.printStackTrace();
- }
- ObjectOutputStream obo=null;
- try {
- obo=new ObjectOutputStream(new FileOutputStream("d:\\readmans.txt"));
- obo.writeObject(readmans);
- } catch (IOException e) {
- e.printStackTrace();
- }finally {
- try {
- obo.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- //借阅的文件操作
- public void fileborrows(){
- try {
- BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("d:\\borrows.txt",false));
- bufferedWriter.write("");
- bufferedWriter.write("");
- //以上是清空之前的操作,以便于我们重新输入
- } catch (Exception e) {
- e.printStackTrace();
- }
- ObjectOutputStream obo=null;
- try {
- obo=new ObjectOutputStream(new FileOutputStream("d:\\borrows.txt"));
- obo.writeObject(bookBorrows);
- } catch (IOException e) {
- e.printStackTrace();
- }finally {
- try {
- obo.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- public void add(){
- System.out.println("========请添加图书信息=========");
- System.out.println("例如:1205 三国演义 罗贯中 清华 2001-1-3 10 99");
- String bookname;
- String writername;
- String publisher;//出版社
- String publishtime;//出版社日期
- int number = 0;//馆藏数量
- int price = 0;
- int booknum=0;
- booknum=myScanner.nextInt();
- bookname=myScanner.next();
- writername=myScanner.next();
- publisher=myScanner.next();
- publishtime= myScanner.next();
- number=myScanner.nextInt();
- price=myScanner.nextInt();
-
- Books book=new Books(booknum,bookname,writername, publisher
- , publishtime, number,price);
- int r=0;
- if(books.size()!=0){
- for (int i=0;i<books.size();i++){
- Books book1=books.get(i);
- if(book1.equalsTwo(book)){
- r++;
- }
- }}
- if(r==0){
- books.add(book);
- System.out.println("图书添加成功!");
- }else{
- System.out.println("图书添加失败!");
- }
-
- }
- public void look() {
- boolean lp=true;
-
- outFile();
- while (lp) {
- rr=true;
- System.out.println("1.根据书名查找");
- System.out.println("2.根据作者名查找");
- System.out.println("3.根据出版社查找");
- System.out.println("=====请输入序号=====");
- int a;
- char y = '1';
- y = myScanner.next().charAt(0);
- if(!Character.isDigit(y)){
- System.out.println("输入错误,请重新输入!");
- }
- if (Character.isDigit(y)) {
- String s = String.valueOf(y);
- a = Integer.parseInt(s);
-
- switch (a) {
- case 1:
- String name;
- System.out.println("请输入书名~");
- name = myScanner.next();
- if (books.size() == 0) {
- System.out.println("目前图书馆没有书籍~");
- return;
- }
- int u = 0;//
-
- //
- ObjectInputStream obi=null;
- try {
- obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
-
- Vector<Books> book =(Vector<Books>)obi.readObject();
- for(Books books1:book){
- if(books1.getBookname().equals(name)){
- System.out.println(books1);
- u++;
- }
-
- }
-
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- //}
- //u++;
- // }
- }
- if (u == 0) {
- System.out.println("没有该书籍");
- }
-
- while (rr) {
- System.out.println("是否继续查找?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- int t;
- char w = '1';
- y = myScanner.next().charAt(0);
- if (Character.isDigit(y)) {
- String d = String.valueOf(y);
- t = Integer.parseInt(d);
- switch (t) {
- case 1:
- rr=false;
- break;
- case 2:
- lp = false;
- rr=false;
- break;
- default:
- System.out.println("输入错误!!!");
- break;
- }
- }
- }
- break;
- case 2:
- String name1;
- System.out.println("请输入作者名~");
- name = myScanner.next();
- if (books.size() == 0) {
- System.out.println("目前图书馆没有书籍~");
- return;
- }
- int u1 = 0;
-
- ObjectInputStream obi1=null;
- try {
- obi1=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
-
- Vector<Books> book =(Vector<Books>)obi1.readObject();
- for(Books books1:book){
- if(books1.getWritername().equals(name)){
- System.out.println(books1);
- u1++;
- }
-
- }
-
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }finally {
- try {
- obi1.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- //}
- //u++;
- // }
- }
- if (u1 == 0) {
- System.out.println("没有该书籍");
- }
-
- while (rr) {
- System.out.println("是否继续查找?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- int t;
- char w = '1';
- w = myScanner.next().charAt(0);
- if (Character.isDigit(w)) {
- String d = String.valueOf(w);
- t = Integer.parseInt(d);
- switch (t) {
- case 1:
- rr=false;
- break;
- case 2:
- lp = false;
- rr=false;
- break;
- default:
- System.out.println("输入错误!!!");
- break;
- }
- }
- }
- break;
- case 3:
- String name11;
- System.out.println("请输入出版社名称~");
- name = myScanner.next();
- if (books.size() == 0) {
- System.out.println("目前图书馆没有书籍~");
- return;
- }
- int u11 = 0;
- ObjectOutputStream obo11=null;
- try {
- obo11=new ObjectOutputStream(new FileOutputStream("d:\\books.txt"));
- obo11.writeObject(books);
- } catch (IOException e) {
- e.printStackTrace();
- }finally {
- try {
- obo11.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
- ObjectInputStream obi11=null;
- try {
- obi11=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
-
- Vector<Books> book =(Vector<Books>)obi11.readObject();
- for(Books books1:book){
- if(books1.getPublisher().equals(name)){
- System.out.println(books1);
- u11++;
- }
-
- }
-
- } catch (IOException | ClassNotFoundException e) {
- e.printStackTrace();
- }finally {
- try {
- obi11.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
- if (u11 == 0) {
- System.out.println("没有该书籍");
- }
-
- while (rr) {
- System.out.println("是否继续查找?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- int t;
- char w1 = '1';
- w1 = myScanner.next().charAt(0);
- if (Character.isDigit(w1)) {
- String d = String.valueOf(w1);
- t = Integer.parseInt(d);
- switch (t) {
- case 1:
- rr=false;
- break;
- case 2:
- lp = false;
- rr=false;
- break;
- default:
- System.out.println("输入错误!!!");
- break;
- }
- }
- }
- break;
- default:
- System.out.println("输入错误!!!");
-
- }
- }
-
-
- }
-
- }
- public void qsort(){
- //排序
- boolean lpp=true;
-
- while(lpp){
- boolean ee=true;
- System.out.println("请输入排序方法");
- System.out.println("1.按照书号");
- System.out.println("2.按照书名");
- int a;
- char y = '1';
- y = myScanner.next().charAt(0);
- if (Character.isDigit(y)) {
- String s = String.valueOf(y);
- a = Integer.parseInt(s);//重点,运用多次,判断输入是否为数字
- switch (a) {
- case 1:
- Collections.sort(books, new Comparator<Books>() {
- @Override
- public int compare(Books o1, Books o2) {
- return o1.getBooknum() - o2.getBooknum();
- }
- });
- for (Books book : books) {
- System.out.println(book);
- }
- while (ee) {
- System.out.println("是否继续排序?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- int t;
- char w = '1';
- y = myScanner.next().charAt(0);
- if (Character.isDigit(y)) {
- String d = String.valueOf(y);
- t = Integer.parseInt(d);
- switch (t) {
- case 1:
- ee=false;
- break;
- case 2:
- lpp = false;
- ee=false;
- break;
- default:
- System.out.println("输入错误!!!");
- break;
- }
- }
- }
- break;
- case 2:
- Collections.sort(books, new Comparator<Books>() {
- @Override
- public int compare(Books o1, Books o2) {
- return o1.getBookname().compareTo(o2.getBookname());
- }
- });
- for (Books book : books) {
- System.out.println(book);
- }
- while (ee) {
- System.out.println("是否继续排序?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- int t;
- char w = '1';
- y = myScanner.next().charAt(0);
- if (Character.isDigit(y)) {
- String d = String.valueOf(y);
- t = Integer.parseInt(d);
- switch (t) {
- case 1:
- ee=false;
- break;
- case 2:
- lpp = false;
- ee=false;
- break;
- default:
- System.out.println("输入错误!!!");
- break;
- }
- }
- }
- break;
- default:
- System.out.println("输入错误");
- break;
- }
- }
- }
-
-
- }
- public void modify(){
- boolean op=true;
- boolean uu=true;
-
- while(op) {
-
- System.out.println("请输入按照书号or书名搜索修改");
- System.out.println("1.书号");
- System.out.println("2.书名");
- System.out.println("3.退出");
- String s= myScanner.next();
- Vector<Books> books1=new Vector<>();
- if(panduan(s)){
- int a=Integer.parseInt(s);
- switch (a){
- case 1:
- System.out.println("================");
- System.out.println("请输入书号~");
- String ss=myScanner.next();
- if(panduan(ss)){
- int a1=Integer.parseInt(ss);
- int y=0;
- ObjectInputStream obi=null;
- try {
- obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
-
- Vector<Books> book11=(Vector<Books>)obi.readObject();
- for (int i=0;i<book11.size();i++){
- Books book=book11.get(i);
- if(book.getBooknum()==a1){
- books1.add(book);
- books.remove(i);
- y++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- if(y==0){
- System.out.println("没有找到该书籍!");
- }else{
- while(uu) {
- boolean ppp=true;
- System.out.println("请输入要修改的内容");
- System.out.println("1.书号");
- System.out.println("2.书名");
- System.out.println("3.作者名");
- System.out.println("4.删除该书籍");
- int t=1;
- char aa=myScanner.next().charAt(0);
- if(Character.isDigit(aa)){
- t=Integer.parseInt(String.valueOf(aa));
- switch (t){
- case 1:
- System.out.println("请输入书号:");
- int number=0;
- number=myScanner.nextInt();
- for(int i=0;i<books1.size();i++){
- Books bookss=books1.get(i);
- bookss.setBooknum(number);
- books.add(bookss);
- }
- System.out.println("修改成功~");
- while(ppp){
- System.out.println("是否继续修改?");
- System.out.println("1.是");
- System.out.println("2.否");
- int cc=2;
- char dc=myScanner.next().charAt(0);
- if(Character.isDigit(dc)){
- cc=Integer.parseInt(String.valueOf(dc));
- switch (cc){
- case 1:
- ppp=false ;
- break;
- case 2:
- ppp=false;
- uu=false;
- op=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
- break;
- case 2:
- System.out.println("请输入书名:");
-
- String name1=myScanner.next();
- for(int i=0;i<books1.size();i++){
- Books book4=books1.get(i);
- book4.setBookname(name1);
- books.add(book4);
- }
- System.out.println("修改成功~");
- while(ppp){
- System.out.println("是否继续修改?");
- System.out.println("1.是");
- System.out.println("2.否");
- int cc=2;
- char dc=myScanner.next().charAt(0);
- if(Character.isDigit(dc)){
- cc=Integer.parseInt(String.valueOf(dc));
- switch (cc){
- case 1:
- ppp=false ;
- break;
- case 2:
- ppp=false;
- uu=false;
- op=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
- break;
- case 3:
- System.out.println("请输入作者名:");
- String name2=myScanner.next();
- for(int i=0;i<books1.size();i++){
- Books book41=books1.get(i);
- book41.setWritername(name2);
- books.add(book41);
- }
- System.out.println("修改成功~");
- while(ppp){
- System.out.println("是否继续修改?");
- System.out.println("1.是");
- System.out.println("2.否");
- int cc=2;
- char dc=myScanner.next().charAt(0);
- if(Character.isDigit(dc)){
- cc=Integer.parseInt(String.valueOf(dc));
- switch (cc){
- case 1:
- ppp=false ;
- break;
- case 2:
- ppp=false;
- uu=false;
- op=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
-
- break;
- case 4:
-
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else {
- System.out.println("输入错误!");
- }
-
- }
- }
- }
- break;
- case 2: System.out.println("================");
- System.out.println("请输入书名~");
- String sss=myScanner.next();
-
-
- int y=0;
- ObjectInputStream obi=null;
- try {
- obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
-
- Vector<Books> book11=(Vector<Books>)obi.readObject();
- for (int i=0;i<book11.size();i++){
- Books book=book11.get(i);
- if(book.getBookname().equals(sss)){
- books1.add(book);
- books.remove(i);
- y++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- if(y==0){
- System.out.println("没有找到该书籍!");
- }else{
- while(uu) {
- boolean ppp=true;
- System.out.println("请输入要修改的内容");
- System.out.println("1.书号");
- System.out.println("2.书名");
- System.out.println("3.作者名");
- System.out.println("4.删除该书籍");
- int t=1;
- char aa=myScanner.next().charAt(0);
- if(Character.isDigit(aa)){
- t=Integer.parseInt(String.valueOf(aa));
- switch (t){
- case 1:
- System.out.println("请输入书号:");
- int number=0;
- number=myScanner.nextInt();
- for(int i=0;i<books1.size();i++){
- Books bookss=books1.get(i);
- bookss.setBooknum(number);
- books.add(bookss);
- }
- System.out.println("修改成功~");
- while(ppp){
- System.out.println("是否继续修改?");
- System.out.println("1.是");
- System.out.println("2.否");
- int cc=2;
- char dc=myScanner.next().charAt(0);
- if(Character.isDigit(dc)){
- cc=Integer.parseInt(String.valueOf(dc));
- switch (cc){
- case 1:
- ppp=false ;
- break;
- case 2:
- ppp=false;
- uu=false;
- op=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
- break;
- case 2:
- System.out.println("请输入书名:");
-
- String name1=myScanner.next();
- for(int i=0;i<books1.size();i++){
- Books book4=books1.get(i);
- book4.setBookname(name1);
- books.add(book4);
- }
- System.out.println("修改成功~");
- while(ppp){
- System.out.println("是否继续修改?");
- System.out.println("1.是");
- System.out.println("2.否");
- int cc=2;
- char dc=myScanner.next().charAt(0);
- if(Character.isDigit(dc)){
- cc=Integer.parseInt(String.valueOf(dc));
- switch (cc){
- case 1:
- ppp=false ;
- break;
- case 2:
- ppp=false;
- uu=false;
- op=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
- break;
- case 3:
- System.out.println("请输入作者名:");
- String name2=myScanner.next();
- for(int i=0;i<books1.size();i++){
- Books book41=books1.get(i);
- book41.setWritername(name2);
- books.add(book41);
- }
- System.out.println("修改成功~");
- while(ppp){
- System.out.println("是否继续修改?");
- System.out.println("1.是");
- System.out.println("2.否");
- int cc=2;
- char dc=myScanner.next().charAt(0);
- if(Character.isDigit(dc)){
- cc=Integer.parseInt(String.valueOf(dc));
- switch (cc){
- case 1:
- ppp=false ;
- break;
- case 2:
- ppp=false;
- uu=false;
- op=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
-
- break;
- case 4:
-
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else {
- System.out.println("输入错误!");
- }
-
- }
- }
-
- break;
- case 3:
-
- uu=false;
- op=false;
- break;
- default:
- System.out.println("请重新输入!");
- break;
- }
- }else{
- System.out.println("输入错误,请重新输入!");
- }
- }//while的结束
- }
- public void addReadman(){
- System.out.println("=====请输入读者信息=====");
- System.out.println("例如:20102010 李华 山农 计算机类8班");
- long number=myScanner.nextLong();
- String name1 =myScanner.next();
- String college=myScanner.next();
- String majorclass=myScanner.next();
- readman man=new readman(number,name1,college,majorclass);
- int gg=0;
- if(readmans.size()!=0) {
- for(int i=0;i<readmans.size();i++) {
- readman rman=readmans.get(i);
- if(rman.equalsT(man)){
- gg++;
- }
- }
- }
- if(gg==0){
- readmans.add(man);
- System.out.println("添加读者信息成功~");
- }
- else System.out.println("读者添加失败!");
-
- }
- public void findman(){
- boolean ww=true;
-
- while(ww) {
- System.out.println("请输入查找读者信息方式");
- System.out.println("1.学号");
- System.out.println("2.姓名");
- System.out.println("3.专业班级");
- int w=1;
- char we=myScanner.next().charAt(0);
- if(Character.isDigit(we)){
- w=Integer.parseInt(String.valueOf(we));
- switch (w){
-
- case 1:
- System.out.println("请输入学号:");
- long num = myScanner.nextLong();
- int nn=0;
- ObjectInputStream obi = null;
- try {
- obi = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
- Vector<readman> man = (Vector<readman>) obi.readObject();
- for (int i = 0; i < man.size(); i++) {
- readman man1 = man.get(i);
- if (man1.getNumber() == num) {
- System.out.println(man1);
- nn++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(nn==0){
- System.out.println("未找到该人!");
- }
- boolean rt=true;
- System.out.println("选择继续查询还是退出?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- while(rt){
- int a=0;
- char ae=myScanner.next().charAt(0);
- if(Character.isDigit(ae)){
- a=Integer.parseInt(String.valueOf(ae));
- switch (a){
- case 1:
- rt=false;
- break;
- case 2:
- rt=false;
- ww=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误,请重新输入!");
- }
- }
-
- break;
- case 2:
- System.out.println("请输入姓名:");
- String s1 = myScanner.next();
- ObjectInputStream ob = null;
- int n1=00;
- try {
- ob = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
- Vector<readman> man = (Vector<readman>) ob.readObject();
- for (int i = 0; i < man.size(); i++) {
- readman man1 = man.get(i);
- if (s1.equals(man1.getName())) {
- System.out.println(man1);
- n1++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- ob.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(n1==0){
- System.out.println("未找到此人!");
- }
- boolean rtt=true;
- System.out.println("选择继续查询还是退出?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- while(rtt){
- int a=0;
- char ae=myScanner.next().charAt(0);
- if(Character.isDigit(ae)){
- a=Integer.parseInt(String.valueOf(ae));
- switch (a){
- case 1:
- rtt=false;
- break;
- case 2:
- rtt=false;
- ww=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误,请重新输入!");
- }
- }
- break;
- case 3:
- System.out.println("请输入专业班级:");
- String s2 = myScanner.next();
- ObjectInputStream o = null;
- int n11=0;
- try {
- o = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
- Vector<readman> man = (Vector<readman>) o.readObject();
- for (int i = 0; i < man.size(); i++) {
- readman man1 = man.get(i);
- if (s2.equals(man1.getMajorclass())) {
- System.out.println(man1);
- n11++;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- o.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(n11==0){
- System.out.println("未找到此人!");
- }
- boolean rttt=true;
- System.out.println("选择继续查询还是退出?");
- System.out.println("1.继续");
- System.out.println("2.退出");
- while(rttt){
- int a=0;
- char ae=myScanner.next().charAt(0);
- if(Character.isDigit(ae)){
- a=Integer.parseInt(String.valueOf(ae));
- switch (a){
- case 1:
- rttt=false;
- break;
- case 2:
- rttt=false;
- ww=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误,请重新输入!");
- }
- }
- break;
- default:
- System.out.println("输入错误,重新输入");
- break;
- }
- }else{
- System.out.println("输入错误,重新输入");
- }
-
- }
- }
- public void mansort(){
- boolean ui=true;
- while(ui) {
- System.out.println("请输入排序方式");
- System.out.println("1.学号");
- System.out.println("2.学院");
- int aw=1;
- char bw=myScanner.next().charAt(0);
- if(Character.isDigit(bw)){
- aw=Integer.parseInt(String.valueOf(bw));
- switch (aw){
- case 1:
-
- Collections.sort(readmans, new Comparator<readman>() {
- @Override
- public int compare(readman o1, readman o2) {
- return (int)(o1.getNumber()- o2.getNumber());
- }
- });
- manoutFile();
- for(readman r:readmans){
- System.out.println(r);
- }
- boolean oo=true;
- while(oo){
- System.out.println("是否继续排序?");
- System.out.println("1.是");
- System.out.println("2.否");
- int q=1;
- char qx=myScanner.next().charAt(0);
- if(Character.isDigit(qx)){
- q=Integer.parseInt(String.valueOf(qx));
- switch (q){
- case 1:
- oo=false;
- break;
- case 2:
- oo=false;
- ui=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else {
- System.out.println("输入错误!");
- }
- }
- break;
- case 2:
- Collections.sort(readmans, new Comparator<readman>() {
- @Override
- public int compare(readman o1, readman o2) {
- return o1.getMajorclass().compareTo(o2.getMajorclass());
- }
- });
- for(readman r1:readmans){
- System.out.println(r1);
- }
- manoutFile();
- boolean o=true;
- while(o){
- System.out.println("是否继续排序?");
- System.out.println("1.是");
- System.out.println("2.否");
- int q=1;
- char qx=myScanner.next().charAt(0);
- if(Character.isDigit(qx)){
- q=Integer.parseInt(String.valueOf(qx));
- switch (q){
- case 1:
- o=false;
- break;
- case 2:
- o=false;
- ui=false;
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else {
- System.out.println("输入错误!");
- }
- }
- break;
- default:
- System.out.println("输入错误!");
- break;
- }
- }else{
- System.out.println("输入错误!");
- }
- }
- }
- public void manmodify(){
- System.out.println("请输入读者的学号");
- long num=myScanner.nextLong();
- System.out.println("请输入读者的姓名");
- String name=myScanner.next();
- ObjectInputStream obi = null;
- Vector<readman> vc = null;
- Vector<readman> rt=new Vector<>();
- readman one=null;
- int y=0;
- try {
- obi = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
- vc = (Vector<readman>) obi.readObject();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- for(int i=0;i<vc.size();i++){
- readman er=vc.get(i);
- if(er.getNumber()==num&&name.equals(er.getName())){
- one=er;
- y++;
- readmans.remove(i);
- }
- }
- if(y==0){
- System.out.println("没有找到此人");
- }else {
- boolean uu = true;
- while (uu) {
- if(readmans.size()!=0){
- System.out.println("请输入要修改的内容");
- System.out.println("1.学号");
- System.out.println("2.姓名");
- System.out.println("3.学院");
- System.out.println("4.专业班级");
- System.out.println("5.删除此人");
- System.out.println("6.退出");
- int a = 1;
- char aa = myScanner.next().charAt(0);
- if (Character.isDigit(aa)) {
- a = Integer.parseInt(String.valueOf(aa));
- switch (a) {
- case 1:
- long num1;
- System.out.println("请输入修改的学号:");
- num1 = myScanner.nextLong();
- one.setNumber(num1);
- readmans.add(one);
- manoutFile();
- System.out.println("修改成功!");
- break;
- case 2:
- String name01 = null;
- System.out.println("请输入修改的名字:");
- name01 = myScanner.next();
- one.setName(name01);
- readmans.add(one);
- manoutFile();
- System.out.println("修改成功!");
- break;
- case 3:
- String name11 = null;
- System.out.println("请输入修改的学院:");
- name11 = myScanner.next();
- one.setCollege(name11);
- readmans.add(one);
- manoutFile();
- System.out.println("修改成功!");
- break;
- case 4:
- String name111 = null;
- System.out.println("请输入修改的专业班级:");
- name111 = myScanner.next();
- one.setMajorclass(name111);
- readmans.add(one);
- manoutFile();
- System.out.println("修改成功!");
- break;
- case 5:
- manoutFile();
- System.out.println("修改成功!");
- break;
- case 6:
- uu = false;
- break;
- default:
- System.out.println("输入错误!");
- break;
-
- }
- } else {
- System.out.println("输入错误!");
- }
- }else{
- uu=false;
- }
-
- }
- }
-
- }
-
-
- public void bookborrow(){
- System.out.println("请输入读者的学号");
- long num=myScanner.nextLong();
- System.out.println("请输入书籍的书号");
- int num1=myScanner.nextInt();
- ObjectInputStream obi =null;
- ObjectInputStream obo=null;
- Vector<Books> boo=null;
- Vector<readman> rea=null;
- Books b1=null;
- readman r1=null;
- try {
- obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
- obo=new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
- boo=(Vector<Books>) obi.readObject();
- rea=(Vector<readman>)obo.readObject();
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- int y=0;
- int x=0;
- for (int i=0;i<rea.size();i++){
- readman r=rea.get(i);
- if(r.getNumber()==num){
- y++;
- r1=r;
- }
- }
- if(y!=0){
- for (int i=0;i<books.size();i++){
- Books b=books.get(i);
- if(b.getBooknum()==num1){
- x++;
- b1=b;
- }
- }
- if(b1!=null){
- if(b1.getNumber()>0){
-
-
- System.out.println("请输入你要借几本?");
- int aa;
- String y1 = null;
- y1 = myScanner.next();
- if (panduan(y1)) {
-
- aa = Integer.parseInt(y1);//重点,运用多次,判断输入是否为数字
- if(b1.getNumber()-aa>=0) {
- //System.out.println("222222");
- books.remove(b1);
- b1.setNumber(b1.getNumber() - aa);
- books.add(b1);
-
- LocalDateTime ldt = LocalDateTime.now();
- String time = ldt.getYear() + "年 " + ldt.getMonthValue() + "月 " + ldt.getDayOfMonth() + "日 " + ldt.getHour() + "时 " + ldt.getMinute() + "分 " + ldt.getSecond() + "秒\n";
- BookBorrow bookBorrow = new BookBorrow(r1.getName(), r1.getNumber(), b1.getBooknum()
- , b1.getBookname(), time, "无");
- bookBorrows.add(bookBorrow);
- fileborrows();
- outFile();
- System.out.println("借书成功!");
- }else{
- System.out.println("借书失败!"+" 该书目前有"+b1.getNumber()+"本");
- }
- }else{
- System.out.println("输入错误!");
- }
-
- }
- else{
- System.out.println("书籍已被借完!");
- }}else{
- System.out.println("未找到此人或此书籍!");
- }
- }else{
- System.out.println("未找到此人或此书籍!");
- }
-
-
- }
- public void bookreturn (){
- System.out.println("请输入归还者的学号");
- long num=myScanner.nextLong();
- System.out.println("请输入归还书籍的书号");
- int num1=myScanner.nextInt();
- BookBorrow bb = null;
- for (int i = 0; i < bookBorrows.size(); i++) {
- BookBorrow b = bookBorrows.get(i);
- if ((b.getMannumber()==num) && (b.getBooknumber()==num1)) {
- bb = b;
- bookBorrows.remove(b);
- }
- }
- if (bb != null) {
- LocalDateTime ldt1 = LocalDateTime.now();
- String time1 = ldt1.getYear() + "年 " + ldt1.getMonthValue() + "月 " + ldt1.getDayOfMonth() + "日 " + ldt1.getHour() + "时 " + ldt1.getMinute() + "分 " + ldt1.getSecond() + "秒\n";
- bb.setReturntime(time1);
- bookBorrows.add(bb);
- fileborrows();
- System.out.println("已全部归还!");
- } else {
- System.out.println("未借该书籍,不用还书");
- }
-
- }
- //图书借阅查询,直接放在了menu case11里面了
- if(bookBorrows.size()!=0){
- fileborrows();
- for (BookBorrow b:bookBorrows){
- System.out.println(b);
- }
- }else{
- System.out.println("现在表中没有信息!");
- }
12.图书全部展示:
// 因为代码并不长,也是直接放了 menu的case12里面了
-
- if(books.size()!=0){
- outFile();
- ObjectInputStream obi=null;
- try {
- obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
- Vector<Books> books20=(Vector<Books>)obi.readObject();
- for(int i=0;i<books20.size();i++){
- Books book9=books20.get(i);
- System.out.println(book9);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- try {
- obi.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }else {
- System.out.println("图书馆现在没有书籍");
- }
System.out.println("已退出图书管理系统!");
这是java基础的一个小项目,能够体现基础知识的把握,做这个之前并没有学Mysql,所以就用到了io流。还在继续加油中~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。