Current location - Training Enrollment Network - Books and materials - Writing Library Book Lending Management System with java
Writing Library Book Lending Management System with java
-

I changed three places for you:

In the 1.borrowBooks method, put System.out.println ("Do you want to borrow it?" ); Replace with:

System.out.println ("Do you want to borrow it? Enter 1 for loan, and enter other numbers without loan. ”);

When you enter, you must enter a number, otherwise you will report an error.

2. In the 2.borrowBooks method, set self [score] = all [9]; Changed to: self [score] = all [I];

If it is all [9], it will always be the information of the last book.

3. In the 3.have method, you want to print out all the information of the borrowed books. A lot of changes, the following note code is original.

void have(Books[] self) {

//for(int I = 0; I<2; i++) {

// self[i]。 showBookInfo();

// }

for(int I = 0; I<3; i++) {

if(self[i]! = empty)

Self [me]. showBookInfo();

}

}

* * * * * * * * * * * * * * All codes have been attached: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *.

Import java.util.scanner;

Public class test manual {

Public static void main(String[] args) {

Books all[] = new book [10];

Books self[] = new book [3];

All [0] = newbooks ("Java", 1, "12345", "Tom", 34.0f, "People's Publishing House");

All [1] = new book ("C", 2, "12346", TNN, 3 1.0f, "People's Publishing House");

All [2] = new book ("C++", 3, "12445", "MM", 35.0f, "People's Publishing House");

All [3] = new book (C #, 4, 12365, TT, 38.0f, People's Publishing House);

All [4] = New Books (J2SE, 5, 13345, TOSM, 3 1. 1f, People's Publishing House);

All [5] = new books (J2EE, 6, 18345, TTM, 32.0f, People's Publishing House);

All [6] = new book ("JSP", 7, "12335", "CC", 33.0f, "People's Publishing House");

All [7] = newbooks ("net ",8," 1234 1 ","bb ",36.0f," People's Publishing House ");

All [8] = new book ("IP", 9, "12343", "AA", 37.0f, "People's Publishing House");

All [9] = new book (TCP, 10, 22345, jj, 39.0f, People's Publishing House);

Reader r = new reader ("Xiao Ming", 10 1, "1", 3);

R.searchAllBooks (all);

R.borrowBooks (all, yourself);

R.have (self);

r.give(all,self);

}

}

Class readers {

Scanner scan = new scanner (system. in);

String name;

int nums

String class;

Int grade;

Int score = 0;

//Books self[]= new book [3];

Readers(String n,int u,String c,int g) {

names = n;

nums = u;

class = c;

Grade = g;;

}

Void search all books (books [] all) {//Find books.

for(int I = 0; I< 10; i++)

All [me]. showBookInfo();

//self[score]= all[0];

}

Void give (books [] all,books [] self) {//

System.out.println ("Please enter the book number of the book you want to return");

int n = scan . nextint();

for(int I = 0; I< 10; i++) {

if (n == all[i]。 num) {

for(int j = 0; j & lt3; j++) {

if (self[j] == all[i]) {

self[j]= null;

System.out.println ("Book returned successfully");

}

}

}

}

}

void have(Books[] self) {

//for(int I = 0; I<2; i++) {

// self[i]。 showBookInfo();

// }

for(int I = 0; I<3; i++) {

if(self[i]! = empty)

Self [me]. showBookInfo();

}

}

void giveMoney() {

}

Books[] all, Books[] self) {

System.out.println ("Please enter the title you are looking for:");

string n = scan . next();

int I;

for(I = 0; I< 10; i++) {

If (n n. equals (all[i]). Name)) {

All [me]. showBookInfo();

Break;

}

}

//System.out.println ("Do you want to borrow it?" );

System.out.println ("Do you want to borrow it? Enter 1 for loan, and enter other numbers without loan. ”);

int j;

j = scan . nextint();

if (j == 1) {

System.out.println ("successful loan");

//self[score]= all[9];

self[score]= all[I];

Score+=1;

}

If (score & lt4) {

System.out.println ("you can still borrow" +(3 points)+"Ben");

} Otherwise {

System.out.println ("Sorry, one person can only borrow three copies");

}

}

}

Classroom books {

String name;

int num

String ISBN

String writer;

Floating price;

String publisher;

Books (string n, int u, string I, string w, floating point p, string l) {

name = n;

num = u;

ISBN = I;

writer = w;

Price = p;;

publisher = l;

}

void showBookInfo() {

system . out . println(" * * * * * * * * * * * * * * * * * * * * * * *);

system . out . println(" title:"+name);

System.out.println ("call number:"+num);

System.out.println("ISBN number: "+ISBN);

system . out . println(" price:"+price);

system . out . println(" publisher:"+publisher);

system . out . println(" * * * * * * * * * * * * * * * * * * * * * * *);

}

}

-