I have 2 arrays that store members and books in a library, i want to use a 3rd array to take information out of those arrays. E.g take one member and one book and put them in one "Loan" slot to represent a member borrowing a book.
Here is all my code
Any help would be much appreciated.
Thanks
import java.util.ArrayList; /** * Write a description of class Library here. * * @author (your name) * @version (a version number or a date) */ public class Library { ArrayList<Membership> member; ArrayList<Books> book; ArrayList<Loans>loan; private int nextMemberID; private int nextBookId; private int nextLoanId; /** * Constructor for objects of class Library */ public Library() { nextMemberID = 1; nextBookId = 1; nextLoanId = 1; member = new ArrayList<Membership>(); book = new ArrayList<Books>(); loan = new ArrayList<Loans>(); } /** * Return the lot with the given number. Return null * if a lot with this number does not exist. * @param lotNumber The number of the lot to return. */ public void addnewMember( String first, String last, String telephone) { member.add(new Membership(nextMemberID,first,last,telephone)); nextMemberID++; } [SIZE="3"][B]public void addnewLoan( ) { loans.add(new Loans();[/B][/SIZE] } public void listMembers() { for(Membership membership : member) { System.out.println(membership.toString()); } } public void getMemberDetails(int ID) { for(Membership membership : member) { if(membership.getID() == ID){ System.out.println (membership); } } // if ID number does not exist then do nothing } public void getBookDetails(int bookid) { for(Books books : book) { if(books.getBookid() == bookid){ System.out.println (books); } } // if ID number does not exist then do nothing } /** * Return the lot with the given number. Return null * if a lot with this number does not exist. * @param lotNumber The number of the lot to return. */ public Membership getMember(int ID) { for(Membership membership : member) { if(membership.getID() == ID){ return membership; } else if (membership.getID() > ID) { System.out.println("Lot number: " + ID + "does not exist."); } } return null; //if there are no lots } /** * Remove the lot with the given lot number. * @param number The number of the lot to be removed * @return The Lot with the given number, or null if * there is no such lot. */ public void removeMember(int ID) { //First we find the lot with the given number Membership membership = getMember(ID); if (membership != null) { //Then we can use the method remove with lot as argument member.remove(membership); } } /** * Return the lot with the given number. Return null * if a lot with this number does not exist. * @param boolean fiction IS the book fiction true or false. */ public void addnewBook( String title, String author, boolean fiction) { book.add(new Books(nextBookId,title,author,fiction)); nextBookId++; } public void listBooks() { for(Books books : book) { System.out.println(books.toString()); } } public Books getBookid(int bookid) { for(Books books : book) { if(books.getBookid() == bookid){ return books; } else if (books.getBookid() > bookid) { System.out.println("Lot number: " + bookid + "does not exist."); } } return null; //if there are no lots } public void removeBook(int bookid) { //First we find the lot with the given number Books books = getBookid(bookid); if (books != null) { //Then we can use the method remove with lot as argument book.remove(books); } } public void searchForLastName(String lastname) { int index = 0; boolean found = false; for(Membership membership : member) { if(membership.getlastName().contains(lastname)) { found = true; } else { index++; } if(found) { System.out.println (membership); } else { // if no matches are found then do nothing } } } public void searchForBookTitle(String booktitle) { int index = 0; boolean found = false; for(Books books : book) { if(books.gettitle().contains(booktitle)) { found = true; } else { index++; } if(found) { System.out.println (books); } else { // if no matches are found then do nothing } } } }
public class Books { // instance variables - replace the example below with your own private final int bookid; private String title; private String author; private boolean fiction; /** * Constructor for objects of class Booklist */ public Books(int Id, String title, String author, boolean fiction) { this.bookid = Id; this.title = title; this.author = author; this.fiction = fiction; } /** * @return The lot's number. */ public int getBookid() { return bookid; } public String gettitle() { return title; } public String toString() { String details = bookid + ": <<<Book ID :Title " + title + " :Author " + author + " :Is the book fiction - True or False? "+ fiction; return details; } }
public class Membership { private String firstName; private String lastName; private String telephoneNumber; private int ID; /** * Constructor for objects of class Member */ public Membership(int ID, String first, String last, String telephone) { this.ID = ID; this.firstName = first; this.lastName = last; this.telephoneNumber = telephone; } /** * @return The lot's number. */ public int getID() { return ID; } public String getlastName() { return lastName; } public String toString() { String details = ID + ": <<<Membership ID :First Name " + firstName + " :Second Name " + lastName + " :Telephone Number " + telephoneNumber; return details; } }