Forums Register Login

Need help with Library program

+Pie Number of slices to send: Send

I am very new to Java and I am having a lot of issues in the online class that I am taking. I have asked my instructor for help on several occasions but the answers that he provides don't make a lot of sense to me (possibly because i am so new...). I have a home work assignment where i need to retrieve the information for three books( Title, Author, ISBN, Price). I then have to make another program that stores the information in both an array and ArrayList.
I know that i am missing setters in this code, but i honestly do not know what i am supposed to add. Here is the program that stores the book information:

Any help would be great!
+Pie Number of slices to send: Send
It isn't really clear what your issue is. Do you have a specific question? Is there an error message you get? Unfortunately, forums aren't a real substitute for a tutor, and so don't make for a good place to ask 'please explain the concepts until I under stand them' types of questions. We will be able to help much better if you ask specific questions that have answers.

Not only does posting specific questions help the forum help you, but it also helps you think in small, discreet steps which is a requirement for writing code anyway. So it is win-win
+Pie Number of slices to send: Send
I guess the question that I have is how to make the library program read the book information from the second program?
+Pie Number of slices to send: Send
What second program? I see two classes. A Book class which holds info about a book. I see a class named BookTestDriver which has a main() method. I only see one main method so I only see one program. The main method creates a bunch of books and puts them in a list and in an array. So what do you want to do?

You should be aware that programming is a language exercise. You need to communicate clearly and precisely the steps you want to do. Before you start programming you should be able to clearly communicate your intent in English (or whatever your native tongue is). If you can't do that then there is no way that you will be able to translate your intent into the Java language.
+Pie Number of slices to send: Send
I am honestly trying. I came to this site because it was supposed to be friendly to beginners.
I need the Book class to call the information(Title,Author, ISBN, and Price) from the BookTestDriver class and print it out. I have to use these two different classes per my instructor.I have tried to adjust the code. Here is what I have now:

Then the code for the BookTestDriver Class:
This is the error that i get when i try to run the program:
" Exception in thread "main" java.lang.StackOverflowError
at library.Book.getTitle(Book.java:23)"
The second line repeats over and over.

I am sorry that i used the incorrect "language" to describe my problem. This is the first java class that i have ever taken. I know that I do not know much but I am trying. I have spent countless hours trying to write this code. I do not need you to make me feel more stupid than i already feel. I came to this site out of desperation. At least i am trying to understand and write my own code instead of copying it from somewhere on the internet.
+Pie Number of slices to send: Send
 

Lizz Hill wrote:I am honestly trying. I came to this site because it was supposed to be friendly to beginners.


I hope you don't think I was being mean... I was just trying to get you to think about and then communicate the problem...

This is the error that i get when i try to run the program:
" Exception in thread "main" java.lang.StackOverflowError
at library.Book.getTitle(Book.java:23)"
The second line repeats over and over.


The 'Stack' is a section of memory Java uses to hold the sequence of method calls. Each time a method is called it is 'added to the Stack' and when it finishes it is 'popped' or removed from the stack. A stack overflow exception means that you have run out of that portion of memory. This is almost universally caused by an infinite loop: a method which either calls itself or calls another method which then calls the first one - over and over again without any chance of stopping.

You said that the second line repeats over and over again, so you can bet that is the line which is causing the infinite loop. I highlighted that portion of code below:


Do you see why that method would cause an infinite loop? Compare it to what you did for the other methods. What is the differences? Why do you think this one would cause an infinite loop, but getAuthor(), for example, won't?

I am sorry that i used the incorrect "language" to describe my problem.


It isn't that you used the incorrect language to describe your problem, it is that you never said what the problem really was. Just made some vague statements about what you think should happen. What you need to do is be very specific. For example, in this post you posted a specific error message, and that makes it easy to detect and correct the problem.

This is the first java class that i have ever taken. I know that I do not know much but I am trying. I have spent countless hours trying to write this code. I do not need you to make me feel more stupid than i already feel. I came to this site out of desperation. At least i am trying to understand and write my own code instead of copying it from somewhere on the internet.


Keep trying. The intent wasn't to make you feel stupid - that is the last thing I would do. The intent was to prod you to step back and describe what you wanted in English. The hardest part of starting out is getting the concept from your mind into code. The reason that is so tough is because you have all these concepts, but the language (Java) doesn't handle concepts - it handles concrete statements and instructions only.

The prodding I did to get you to be specific was to get you thinking concretely: in small, easy to communicate steps. I suggest you do this in English (or your native language) first because it is what you are most comfortable with. So translate the 'ideas' into 'steps' and make those steps as small as possible. Also, write them down so they are readable. Make sure each step is only a simple sentence. Then you translate those steps into Java - this last translation ends up being (relatively) easy because small concrete steps are what programming languages are good at.
You know it is dark times when the trees riot. I think this tiny ad is their leader:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1129 times.
Similar Threads
Java Inheritance Error
Objects showing null
Castor Help with unmarshalling
Unable to figure out what is stopping my compile
java code problem
A better way to create and sort an array of objects?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:36:08.