This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding & Searching Data ! need help !  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys !

Can someone please guide me, I have created a program but it's incomplete, can anyone tell me what to do further!

The task is:

Write a java program which defines and implements an appropriate set of attributes for a Book class. Implement two polymorphic add() methods for adding a current instance of a Book to an Array and an instance of a book to a another Book object.

The code I wrote:

class book

String BookName;
String Isbn;
int NoOfStock;
String Author;

public static void main(String[]args)

book[] bookdata= new book[10];

bookdata[0]=new book();
bookdata[0].BookName="Visual Basic";

bookdata[1]=new book();
bookdata[1].BookName="Java 2";

for(int i=0; i<2;i++){



What to do NOW ??? I've added the books but how will I add another book and check it ! and can I do it through parameter ?

take care all.
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd work on creating those add() methods.
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is Hard:

Welcome to JavaRanch! Please take a moment to read our Naming Policy, and then
Change your display name to comply. (We are looking for a real-sounding, first and last name (preferrably your real one)).

As far as your question goes:

In actuality, the assignment is pretty poorly written. First, I don't think they mean polymorphic methods, but rather overloaded methods. Then, why are you adding one book to another? This does not make logical sense.... Finally, it should not be the responsibility of the Book to add itself to the array, but the reponsibility of another object (maybe a Library) to add books. But all of these points are neither here nor there; you can't actually change the assignment.

As far as the assignment goes, you need to write two add() methods. The first will place the current instance of a Book into an array, and the second will add the book to another book. So, start by writing the method signatures:

Now, as to the actual implementation of those methods, well, that's an exercise left to the reader.
What are you doing? You are supposed to be reading this tiny ad!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!