Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Please i need help in a simple coding

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please i need help in a simple coding

    I need help with this...

    1) I have a librarian class which he/she can add or remove books to the book lists


    How to did a method so that a librarian can add books and also remove books from the books lists which is stored in the array ? and can i have the sample coding pls ? THX IN ADVANCED...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please i need help in a simple coding

    What code have you written so far? Post your current code and any questions you have.

    What you are describing sounds like a big program with many parts.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    Quote Originally Posted by ookhai View Post
    I need help with this...

    1) I have a librarian class which he/she can add or remove books to the book lists


    How to did a method so that a librarian can add books and also remove books from the books lists which is stored in the array ? and can i have the sample coding pls ? THX IN ADVANCED...
    If I understand correctly, you have a class "librarian" who should, by method, be able to add or remove books from a list?

    If so, you could have something like this:

    [Java] import java.util.Vector; public class Librarian { private Vector <Book> l - Pastebin.com

    For ease of implementation, I have chosen a Vector instead of Array, since the array is immutable in size. You could replace Vector by ArrayList.

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    thx ! blueygh2 ....i think u almost get my mean...this is how my code

    This is my book class : //book clas public class Books { // data members private String booksN - Pastebin.com

    This is my test program : import java.util.Scanner; public class testLibrary { public static void - Pastebin.com


    can pls help me to link the librarian clas which can add book or remove book ? SRY FOR THE LATE REPLY IM BUSYING TO CODE coz im beginner....

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please i need help in a simple coding

    Can you post the code here on the forum so everyone can see it?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    This is my book class :



    public class Books {

    // data members
    private String booksName;
    private String booksAuthor;
    private String booksEdition;
    private int rackNo;

    // constructor
    public Books(String booksName, String booksAuthor, String booksEdition, int rackNo) {
    this.booksName = booksName;
    this.booksAuthor = booksAuthor;
    this.booksEdition = booksEdition;
    this.rackNo = rackNo;
    }
    // toString method
    public String toString() {
    return String.format("\t%-10s %-10s %-10s \t\t%d", booksName, booksAuthor, booksEdition, rackNo);
    }


    }

  7. #7
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    This is my test program :

    import java.util.Scanner;

    public class testLibrary {

    public static void main(String[] args) {
    Books[] booksArr = {new Books("Harry Potter", "\tJ.K ROLLING", "\t\t1st", 1),
    new Books("Hello Kitty", "\tJ.K Kitting", "\t\t2nd", 2),
    new Books("Harry Kitter", "\tJ.K CASDCDC", "\t\t3rd", 3),
    new Books("Harry Popper", "\tJ.K CDDCSWV", "\t\t4th", 4),
    new Books("Happy Monter", "\tJ.K UJYUGNH", "\t\t5th", 5),
    new Books("Marry kiefer", "\tJ.K CVFBVFF", "\t\t6th", 6)};

    System.out.println("\nBooks Lists: ");
    System.out.println("============================== ==============================================");
    System.out.println("No.\tBooks name \t\tBooks author \tBooks edition \tRack number ");
    System.out.println("============================== ==============================================");
    for (int j = 0; j < booksArr.length; ++j) {
    System.out.println((j+1) + ". " + booksArr[j].toString());
    }





    }
    }


    teacher say we are just beginner ...so we may just input a FEW fixed book lists which contains in library..
    Last edited by ookhai; July 1st, 2012 at 09:39 AM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please i need help in a simple coding

    Do you have questions or problems with the code? Please post them.

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    i dun have any problem with the code...which means that the i can show out the books in the test program successfully...........now i need a librarian class which he/she can ADD books to the book list and also REMOVE books from the book list, but i dont know how to did the methods in the librarian class....could u help me ? if can with sample coding pls...

     
    public class Books {
     
        // data members
    	private String booksName;
    	private String booksAuthor;
        private String booksEdition;
        private int rackNo;
     
     	// constructor
    	public Books(String booksName, String booksAuthor, String booksEdition, int rackNo) {
    		this.booksName = booksName;
    		this.booksAuthor = booksAuthor;
    		this.booksEdition = booksEdition;
    		this.rackNo = rackNo;
    	}
    	// toString method
    	public String toString() {
    		return String.format("\t%-10s %-10s %-10s \t\t%d", booksName, booksAuthor, booksEdition, rackNo);
    	}
     
     
    }




    and my test program
     
        import java.util.Scanner;
     
    public class testLibrary {
     
    	public static void main(String[] args) {
      	Books[] booksArr =     {new Books("Harry Potter", "\tJ.K ROLLING", "\t\t1st",   1),
      							new Books("Hello Kitty",  "\tJ.K Kitting", "\t\t2nd",   2),
      							new Books("Harry Kitter", "\tJ.K CASDCDC", "\t\t3rd",   3),
      							new Books("Harry Popper", "\tJ.K CDDCSWV", "\t\t4th",   4),
      							new Books("Happy Monter", "\tJ.K UJYUGNH", "\t\t5th",   5),
      							new Books("Marry kiefer", "\tJ.K CVFBVFF", "\t\t6th",   6)};
     
      	System.out.println("\nBooks Lists:					                                         	");
      	System.out.println("============================================================================");						
      	System.out.println("No.\tBooks name \t\tBooks author \tBooks edition \tRack number              ");
      	System.out.println("============================================================================");	
      		for (int j = 0; j < booksArr.length; ++j) {
      			System.out.println((j+1) + ". " + booksArr[j].toString());
      		}
     
     
     
     
     
    }
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please i need help in a simple coding

    What are the things the librarian class must do? Make a list of what you want it to do and then work on what methods the class will need to have to do for each item in the list.

    Where will the book objects be saved? The librarian class will need to be able to access that location to do its tasks.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    As stated in my practical paper question....."Librarian can add books to the library collection or remove them".......so now my library collection(books list) already done.....left the librarian class with add / remove books method rite? how to did that ?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please i need help in a simple coding

    Take the items one at a time and write the code for it. Work on code to add a book.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    ok lah thx you.....im trying hard now..

  14. #14
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Please i need help in a simple coding

    it was good

Similar Threads

  1. Need Help With Coding
    By noles227 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2012, 07:35 PM
  2. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  3. Need your help to coding
    By Tony_nguyen19 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 14th, 2011, 08:58 AM
  4. i need coding for simple login
    By nag in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: September 29th, 2011, 02:30 PM
  5. [SOLVED] simple question, coding unrelated, how to delete multiple tabs?
    By Perd1t1on in forum Java Theory & Questions
    Replies: 1
    Last Post: September 8th, 2010, 07:44 PM