Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Adding & Searching Data ! need help !

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd work on creating those add() methods.
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
I don't even know how to spell CIA. But this tiny ad does:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic