Need help object of array
Hello,
I need a help, so if someone can tell me what;s wrong or/and explain why i am wrong that's will be nice.
Here is a part my two classes i got an error from my compiler and i don't know what's wrong.
The second thing, could someone tell me how can use those two classes together from a main test class?
here is my error
symbol : variable readerBook
location: class readerBook
readerBook [index] = aBook;
^
1 error
<> My first class (a part of it)
public class readerBook
{
private readerBook[] books;
private int totalBook;
public readerBook()
{
pools = new readerBook[10];
}
private void addBooks(int index, int aBook)
{
readerBook[index] = aBook; << Here i can't understant what's wrong?
}
(...)
<> My second class (a part of it)
public class Booker
{
String name;
int width;
int lenght;
public Booker(String aName, int aWidth, int aLenght, int index)
{
name = aName;
width = aWidth;
lenght = aLenght;
}
(...)
Thanks
[1176 byte] By [
kalifara] at [2007-9-28 13:18:59]

> Hello,
>
> I need a help, so if someone can tell me what;s wrong
> or/and explain why i am wrong that's will be nice.
>
> Here is a part my two classes i got an error from my
> compiler and i don't know what's wrong.
>
> The second thing, could someone tell me how can use
> those two classes together from a main test class?
>
>
> here is my error
>
> symbol : variable readerBook
> location: class readerBook
> readerBook [index] = aBook;
> ^
> 1 error
>
> <> My first class (a part of it)
>
> public class readerBook
>
> {
> private readerBook[] books;
> private int totalBook;
>
>
> public readerBook()
> {
> pools = new readerBook[10];
//books=new readerBook[10];
//you've declared your variable books
> }
>
>
> private void addBooks(int index, int aBook)
> {
>
> readerBook[index] = aBook; << Here i can't understant
> what's wrong?
> // then use your variable
// books[index]=aBook;
> }
>
> (...)
>
>
> <> My second class (a part of it)
>
> public class Booker
>
> {
> String name;
> int width;
> int lenght;
>
>
> public Booker(String aName, int aWidth, int aLenght,
> int index)
> {
> name = aName;
> width = aWidth;
> lenght = aLenght;
> }
>
> (...)
>
>
> Thanks
thanks,i have changed everythings like you ve done it aboveand i got this error now: i got an incompatible typefound : intrequired: readerBookbooks[index] = aBook;^1 error
Hi, againaBook must of course be of the same type as the elements in your arraythat is of type readerBook.likeaddBook(int index,readerBook aBook){ books[index]=abook;}you can't put an int in a array of readerBook!
true, thank you very much for your help, i have really appreciatedcould you tell me where can i get more infos about how to usean array of object?thanks
Hi,a good place to start is Sun's Java tutorial.Happy coding!
hello,thanks a lot , true that is a very good place with examples and so on.
hi,
i have changed a litle bit this code...
addBook(int index,readerBook aBook){
books[index]=abook;
}
and i done like this
public void addBook(String name, int width, int length, int index)
{
Booker aPool = new Booker(name, width, length);
books[index]=abook;
}
do you think this method is correct?
my second problem now is how can i input data from a main test class
i tried to do in the main class something like that
(i have a code just before to input data)
ReaderBook poolOne = ReaderBook ();
bookOne.addBook(aName, aWidth, aLength, index);
bookOne.displayAllBooks();
do you think it is the correct way to do it?
the only problem i have is when i want to display all my book
i have an error that my array is out of bound (excepetion error)
everything is show, i mean all the value, but i can input only once
a time one instance of book name width length
here is my method to display all the Books
public void displayAllbooks()
{
for (int i = 0; i < 10 ; i++)
{
books.displayDetails();
}
}
thank for any help