I have this system which I only want to try and borrow books from a library.
I have data already in arrays.
I need to check that nobody else has a book then add it to the data.
I have commented where i think the problem is.
i have tried syste.out and I jst get the original data that was in the array instead of the added data???
any ideas??
thanks for looking
the code is below
import javax.swing.*;
class LibraryMain {
// Creates a staff of employees
public static void main (String[] args) {
// Sets up the list of books.
Books[] BookList;
BookList = new Books[5];
BookList[0] = new Books("title", "author", "B1");
BookList[1] = new Books("my", "by","B2");
BookList[2] = new Books("lname", "by","B3");
BookList[3] = new Books("lname", "by","B4");
BookList[4] = new Books("lname", "by","B5");
System.out.println("Library System\n");
//creates object to print out details
Borrowers personnel = new Borrowers();
personnel.records();
System.exit(0); //exits
}
}
class Borrowers{
public Students[] BorrowersList;
public Borrowers () {
// Sets up the list of borrowers.
BorrowersList = new Students[4];
BorrowersList[0] = new Students ("adam", "S1","", "");
BorrowersList[1] = new Students ("tim", "S2","B1", "");
BorrowersList[2] = new Students ("Mr", "L3","B5", "");
BorrowersList[3] = new Students ("mrs", "L4","B3", "B5");
for(int count = 0;count<1;count++){ //loop to continue to enter books
//gets student ID
String num = JOptionPane.showInputDialog(null,
"Enter the ID number",
"Library System",
JOptionPane.QUESTION_MESSAGE);
// gets bookid
String num2 = JOptionPane.showInputDialog(null,
"Enter the Book ID",
"Library System",
JOptionPane.QUESTION_MESSAGE);
//finds if any one has that book
for (int count2 =0; count < 4; count++) {
if (BorrowersList[count2].bookid1.equals("num2")){
System.out.println("Book already on loan");
break;
}
else{
num = BorrowersList[count2].bookid1;
// problem here, wont override array??
}
}
}
}
public void records() {
//prints out borrowers details
for (int count=0; count < BorrowersList.length; count++) {
System.out.println (BorrowersList[count]);
System.out.println ("-----------------------------------");
}
}
}
class Students{
protected String name;
protected String ID;
protected String bookid1;
protected String bookid2;
// Sets up students with the information.
public Students (String sName, String sID, String sBookid1, String sBookid2) {
name = sName;
ID = sID;
bookid1 = sBookid1;
bookid2 = sBookid2;
}
// Returns information about the students as a string.
public String toString() {
String result = "Name : " + name + "\n";
result += "ID : " + ID + "\n";
result += "Books borrowed: " + bookid1 + bookid2 ;
return result;
}
}
class Books{
protected String title;
protected String author;
protected String ISBN;
// Sets up books with the information.
public Books (String sName, String sID, String sBookid) {
title = sName;
author = sID;
ISBN = sBookid;
}
}
Code tags added. -Narue