public void addNode( int id, String fName, String lName ) { MemberNode m = new MemberNode( id, fName, lName );
MemberNode current = head;
if ( head == null ) head = m; else { while ( current.next != null ) { current = current.next; }
current.next = m; }
}
public void createNodeFromFile( String str ) { StringTokenizer t = new StringTokenizer( str, "|"); String id = t.nextToken(); String fName = t.nextToken(); String lName = t.nextToken(); int bookId;
MemberNode m = new MemberNode( Integer.parseInt( id ), fName, lName );
for (int i = 0; i < 5; i++ ) { m.books[i] = Integer.parseInt( t.nextToken() ); }
MemberNode current = head;
if ( head == null ) head = m; else { while ( current.next != null ) { current = current.next; }
current.next = m; } }
public boolean removeMember(int key) { MemberNode current = head; MemberNode previous = null;
while (current != null && current.id != key) { previous = current; current = current.next; }
if (current == null) { System.out.println("There's no such member"); return false; } else if (previous == null) head = head.next; else previous.next = current.next;
return true; }
public boolean viewAMember(int key) { MemberNode current = head;
while (current != null) { if (current.id == key) { System.out.println("-----------------------------------------------------------"); System.out.println("ID | First Name | Last Name | Bollowed Books"); System.out.println("-----------------------------------------------------------"); System.out.println(current.id + "\t" + current.fName + "\t" + current.lName + "\t" + current.books); System.out.println("-----------------------------------------------------------"); return true; } current = current.next; } System.out.println("Member's ID cannot be found"); return false; }
public void viewAllMembers() { MemberNode current = head;
System.out.println("-----------------------------------------------------------"); System.out.println("ID | First Name | Last Name | Bollowed Books"); System.out.println("-----------------------------------------------------------"); while ( current != null ) { System.out.println(current.id + "\t" + current.fName + "\t" + current.lName + "\t" + current.books); current = current.next; } System.out.println("-----------------------------------------------------------"); }
}
//book node public class BookNode { BookNode next;
int id; String title; int num;
public BookNode( int id, String title ) { this.id = id; this.title = title; this.num = 2;
next = null; } }
//book list import java.util.*;
public class BookList { BookNode head;
public BookList() { head = null; }
public void addNode( int id, String title ) { BookNode b = new BookNode( id, title );
BookNode current = head;
if ( head == null ) head = b; else { while ( current.next != null ) { current = current.next; }
current.next = b; }
}
public void createNodeFromFile( String str ) { StringTokenizer t = new StringTokenizer( str, "|"); String id = t.nextToken(); String title = t.nextToken(); String num = t.nextToken();
BookNode b = new BookNode( Integer.parseInt( id ), title );
BookNode current = head;
if ( head == null ) head = b; else { while ( current.next != null ) { current = current.next; }
current.next = b; } }
public boolean removeBook(int key) { BookNode current = head; BookNode previous = null;
while (current != null && current.id != key) { previous = current; current = current.next; }
if (current == null) { System.out.println("There's no such book"); return false; } else if (previous == null) head = head.next; else previous.next = current.next;
return true; }
public boolean viewABook(int key) { BookNode current = head;
while (current != null) { if (current.id == key) { System.out.println("-----------------------------------------------------------"); System.out.println("ID | Title | Number of Available Copies"); System.out.println("-----------------------------------------------------------"); System.out.println(current.id + "\t" + current.title + "\t" + current.num); System.out.println("-----------------------------------------------------------"); return true; } current = current.next; } System.out.println("Book's ID cannot be found"); return false; }
public void viewAllBooks() { BookNode current = head;
System.out.println("-----------------------------------------------------------"); System.out.println("ID | Title | Number of Available Copies"); System.out.println("-----------------------------------------------------------"); while ( current != null ) { System.out.println(current.id + "\t" + current.title + "\t" + current.num); current = current.next; } System.out.println("-----------------------------------------------------------"); } }
public class Driver { public static void main(String args[]) throws IOException { int aKey; MemberList memberList = new MemberList(); BookList bookList = new BookList(); boolean start = true; while(start) { System.out.println("Select From the Follwing List"); System.out.println("1 - Add a new member"); System.out.println("2 - Add a new book"); System.out.println("3 - Remove a member"); System.out.println("4 - Remove a book"); System.out.println("5 - borrow a book"); System.out.println("6 - View information about all books"); System.out.println("7 - View information about all members"); System.out.println("8 - View information about a member"); System.out.println("9 - View information about a book");
char choice = getChar();
switch(choice) { case '1': System.out.print("Input member ID : "); int id = getInt(); System.out.print("Input First Name : "); String fName = getString(); System.out.print("Input Last Name : "); String lName = getString(); memberList.addNode(new MemberNode(id,fName,lName)); break;
case '2': System.out.print("Input book ID : "); int id = getInt(); System.out.print("Input book Title : "); String title = getString(); bookList.addNode(new BookNode(id,title)); break;
case '3': System.out.println("Enter a Member ID to delete: "); aKey = getInt(); itemList.removeMember(aKey); break;
case '4': System.out.println("Enter a Book ID to delete: "); aKey = getInt(); itemList.removeBook(aKey); break;
case '5': System.out.println("Enter a Member ID to delete: "); aKey = getInt(); itemList.removeItem(aKey); break;
case 'p': itemList.printDatabase(); break;
case 't': itemList.printTotal(); break;
case 'g': System.out.println("Enter key value to find: "); aKey = getInt(); itemList.printItem(aKey); break;
public class NewMemberDialog extends JDialog implements ActionListener { JLabel lblId = new JLabel("Member id"); JLabel lblFName = new JLabel("First name"); JLabel lblLName = new JLabel("Last Name");
JTextField tfId = new JTextField(15); JTextField tfFName = new JTextField(15); JTextField tfLName = new JTextField(15);
JPanel editPanel = new JPanel();
JButton btnOK = new JButton("OK"); JButton btnCancel = new JButton("Cancel");
boolean ok;
JPanel btnPanel = new JPanel();
public NewMemberDialog(Assignment pfr) { super(pfr, "New member", true ); Container cp = getContentPane();
GridBagLayout gridbag = new GridBagLayout(); editPanel.setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
//setting a default constraint value c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0; //x grid position c.gridy = 0; //y grid position gridbag.setConstraints(lblId, c); //associate the label with a constraint object editPanel.add(lblId); //add it to content pane
c.gridx = 0; //x grid position c.gridy = 1; //y grid position gridbag.setConstraints(lblFName, c); //associate the label with a constraint object editPanel.add(lblFName); //add it to content pane
c.gridx = 0; //x grid position c.gridy = 2; //y grid position gridbag.setConstraints(lblLName, c); //associate the label with a constraint object editPanel.add(lblLName); //add it to content pane
c.gridx = 1; //x grid position c.gridy = 0; //y grid position c.gridwidth = 2; gridbag.setConstraints(tfId, c); //associate the label with a constraint object editPanel.add(tfId); //add it to content pane
c.gridx = 1; //x grid position c.gridy = 1; //y grid position c.gridwidth = 2; gridbag.setConstraints(tfFName, c); //associate the label with a constraint object editPanel.add(tfFName); //add it to content pane
c.gridx = 1; //x grid position c.gridy = 2; //y grid position c.gridwidth = 2; gridbag.setConstraints(tfLName, c); //associate the label with a constraint object editPanel.add(tfLName); //add it to content pane