not getting output
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am doing an assignment for school and I am not understanding why I am not seeing the output from a csv file containing data like author,publisher etc. or showing the list of books.
Any help would be appreciated.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
How do you know you are reading from the file at all? Start by printing each line as you read it from the file. What on earth does the parseBooks method do?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Carolin Sha wrote:the parseBooks method is suppose to return a book object with all of its fields (instance variables) given a value.
Can you show us the correct version of the parseBooks() method? ... because with this version (that you shown), the answer to why "not getting output" would be because it doesn't compile.
Henry
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In line 28 you are calling the parseBook method with a String, but as you can see in line 51 it expects a String[] (an array of strings, not a single string).
In line 51 you specified that the parseBook method returns a Book object, but it doesn't. It's not returning anything.
Since you can't even compile the code, you can't run it either. Please post your actual, compiling code - it's hard to help you if we don't know what your real program looks like.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Carolin Sha wrote:Any help would be appreciated...
Well one thing I notice is that your getScanner() method is "swallowing" an exception. This is generally very bad practise unless your program has some way of recovering from the error.
However, all you do is return null, which means that in the event of an IOException, your program will STILL fail, except that it will throw a NullPointerException instead of the one that it probably should.
If you're trying to avoid adding throws clauses all over the place, you can simply re-throw the exception as a RuntimeException or an Error, eg:however, even that assumes that all exceptions will be due to a bad filename, which may not be the case; so my preference would be to leave the System.err message out altogether.
HIH
Winston
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You do open the file, but you do no parsing of the file. Your parseBook() method simply returns a null book, regardless of the file input lines. This means that your results list of books, is just a list of nulls.
Henry
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Carolin Sha wrote:the task is to edit the parseBooks method to return a book object with all of its fields (instance variables) given a value.
OK, but that method has to return a Book, so where is that class? Or do you have to write that as well?
If so, I suggest you write one with a constructor that takes a "line" and returns a Book. Show us what you've tried.
It would also be useful to have a few examples of lines from your input file.
Winston
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
sorry for late response. the question is write the body of the parseBook() method in the BookCSVParser class, such that the parseBook() method returns a Book object with all of its fields (instance variables) given a value.
This is the code I have so far.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
All things are lawful, but not all things are profitable.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Carolin Sha wrote:the question is write the body of the parseBook() method in the BookCSVParser class, such that the parseBook() method returns a Book object with all of its fields (instance variables) given a value.
OK, but we still haven't seen your Book class yet. Has that also been written, or do you have to write it yourself?
Also (again): it would be nice to see some examples of your input lines.
We need information in order to help you Carolin, and simply repeating the same code doesn't help us much.
And just to remind you: we will help you write the method; we won't do it for you.
Winston
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
myBook.title = ...;
anywhere outside the Book class. Also give the Book class a constructor which can initialise all its fields (or at least most of them).
Agree with Winston about showing us the Book class. When you designed your app you probably started with the Library and then wrote Book. When you write the code however, you should do it the other way round. You should write the Book class and get it working and tested before you can write the Library class.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I know you guys would not do it for me, some things are bit confusing for me. please see the book class which was provided and the AbstractBook class.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Carolin Sha wrote:
I know you guys would not do it for me, some things are bit confusing for me.
Perhaps it would be a good idea to make sure that parseBook() method (of the book parser class) actually compiles first... we can't give you a hint in the right direction, if you are not starting from a place where you can, at least, run your code.
Unless, of course, the issues are the compiler errors. In this case, I would recommend working on the compiler errors in order. Fix the first ones first, and then recompile. And if you are having issues with fixing the compiler error, perhaps you can tell us the error you are having trouble with, what have you tried to fix it, and we can give you a hint.
Henry
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When I compile the original code parseBook() method of the book parser class this is the output.
null
null
null
null
null
null
null
null
null
null
null
The Book class was provided and uploaded earlier. the task at hand is to write the body of the parseBook() method in the BookCSVParser class, such that the parseBook() method returns a Book object with all its fields given a value.
I tried creating the Book object from the parseBook() method since I am supposed to just upload this BookCSVParser class as a deliverable to fulfil the task at hand. Is this approach wrong?
Really confused here.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The Book class was provided and uploaded earlier. the task at hand is to write the body of the parseBook() method in the BookCSVParser class, such that the parseBook() method returns a Book object with all its fields given a value.
Does parseBook() return a Book? Does it take a value?
All things are lawful, but not all things are profitable.
| A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







