Results 1 to 5 of 5
  1. #1
    jbarreto1 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Library Assistant project help

    I need help with checking in a book and checking out a book and I'm also not sure if the code is reading the text file correctly. To check out a book i need to check the status, change the status when a book is checked out/in, check who has the book, and change who has the book. If anyone can help I would greatly appreciate it. If there are any other errors please let me now.

    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;

    public class Library {
    int command;
    private static final int Show_all_library_cards = 1;
    private static final int Show_all_books = 2;
    private static final int Check_out_a_book = 3;
    private static final int Check_in_a_book = 4;
    private static final int Create_a_new_library_card = 5;
    private static final int Exit_the_system = 6;

    public static void main(String[] args) throws FileNotFoundException {

    // declare an array of 20 cards
    String[] Cards = new String [ 20 ];
    // declare an array of 20 books
    String [] Books = new String [ 20 ];
    // declare a file pointer and open the cards file
    Scanner fileinput = new Scanner(new File("cards.txt"));

    // read the next line from the file
    String line = fileinput.nextLine();
    // tokenize the line to get the data for class variables
    String[] tokens = line.split(",");

    Card temp = new Card( tokens[0], tokens[1], Integer.parseInt(tokens[2]), 0 );

    // declare a file pointer and open the books file
    Scanner fileinput1 = new Scanner(new File("books.txt"));
    // read the next line from the file
    String line1 = fileinput.nextLine();
    // tokenize the line to get the data for class variables
    String[] tokens1 = line1.split(",");

    Book temp1 = new Book( tokens1[0], tokens1[1], Integer.parseInt(tokens1[2]), false , 0 );

    // display main menu
    Scanner input = new Scanner(System.in);
    ShowMenu();
    int command = input.nextInt();

    while(command != 0)
    {

    switch ( command )
    {
    case Show_all_library_cards:
    for(int i = 0; i < Cards.length; i++){
    System.out.println(Cards[i]);
    }
    case Show_all_books:
    for(int i = 0; i < Books.length; i++){
    System.out.println(Books[i]);
    }
    case Check_out_a_book:
    System.out.print( "Enter Card ID: ");
    int CardID = input.nextInt();
    System.out.print( "Enter Book ID: ");
    int bookID =input.nextInt();

    case Check_in_a_book:
    System.out.print( "Enter Card ID: ");
    CardID = input.nextInt();
    System.out.print( "Enter Book ID: ");
    bookID =input.nextInt();

    case Create_a_new_library_card:
    for ( int i = 0; i <Cards.length; i++ )
    {
    System.out.print( "Enter Your Name: " + (i+1));
    Cards[i] = input.next();
    System.out.print( "Enter Your Phone Number: " + (i+1) );
    Cards[i] = input.next();
    System.out.print( "Enter Your Card ID: " + (i+1));
    Cards[i] = input.next();
    }
    case Exit_the_system:
    System.out.println( "\nExiting the menu..." );
    break;
    default:
    System.out.println( "\nYou did not enter a valid selection. Try again." );
    break;
    }

    ShowMenu();
    command = input.nextInt();
    }


    }


    public static void ShowMenu()
    {
    System.out.print("\nMain Menu:");
    System.out.print("1 - Show all library cards ");
    System.out.print("2 - Show all books ");
    System.out.print("3 - Check out a book ");
    System.out.print("4 - Check in a book ");
    System.out.print("5 - Create a new library card ");
    System.out.print("6 - Exit the system\n ");
    System.out.print("Enter a choice: ");
    return;
    }
    }

    public class Card {
    private String Name;
    private String Phone;
    private int CardID;
    private int BookID;
    public Card (String Name, String Phone, int CardID, int BookID)
    {
    this.Name = Name;
    this.Phone = Phone;
    this.CardID = CardID;
    this.BookID = BookID;

    }

    }

    public class Book {
    String Booktitle;
    String Author;
    boolean BookCheckout;
    int who_has_the_book;

    public Book(String BookTitle, String Author, int BookID, boolean BookCheckout, int who_has_the_book)
    {
    this.Booktitle = Booktitle;
    this.Author = Author;
    this.BookCheckout = BookCheckout;
    this.who_has_the_book = who_has_the_book;

    }

    }

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Please use the CODE or PHP tags to post code so it keeps its format and is readable.

    What exactly is the question you have ?

  3. #3
    jbarreto1 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    oh sorry. My question is how do I make it check out a book and how to check it back in. how do I make check to see if the card ID and book ID are valid. Then put in the book array the card ID of whoever checkout the book and in the card array put the book # that was check out.

  4. #4
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    That's not really a Java problem, it's a general design problem - without seeing readable code and/or getting an explanation of how the application works, I can't really say. How you do it is up to you. You decide what checking out a book involves, what information you'll need, where you're going to store it, what you're going to do with it, and so on. Similarly for the other tasks.

    When you get stuck with a Java difficulty or you don't understand something, please ask a specific question. If you get error messages or exceptions, post the full error message text and stack trace, if present.

  5. #5
    jbarreto1 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    If you dont mind me asking. how would you do it with the code provided?

Similar Threads

  1. wanna make Library Management project
    By Vinay Bhatia in forum New To Java
    Replies: 5
    Last Post: 12-24-2010, 02:13 AM
  2. I want to put the native library in library path in mac os x
    By Hussain Ali in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2010, 08:55 AM
  3. Tell me jar file for library library org.bouncycastle.cms
    By 82rathi.angara in forum New To Java
    Replies: 10
    Last Post: 09-09-2008, 06:11 AM
  4. Assistant on my codes. SOS!!
    By sya1912 in forum Java Applets
    Replies: 16
    Last Post: 09-01-2008, 03:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •