Carey Brown wrote:It's not clear why UserInput has-a collection of Books.
Agree; there is however a problem. It is likely that the call in line 17 is preceded by nextInt(). In which case there is a risk of nextLine() returning an empty String. If this happens, your inputs will be thrown out of sequence; there is more explanation and a possible solution in this old post. Creating an input utility class would be a much more time‑consuming solution, but I prefer it. Such a class would allow you not to write multiple dot operators (see line 11).Carey Brown wrote:The use of scan.next() on lines 4, 11, and 17 should probably be replaced by scan.nextLine(). . . .
The ISBNs shown are indeed ill‑formed. It would be better to create an ISBN class and make it immutable and do the validation in its constructor than to try using plain Strings.. . . additional logic to reject ill formed ISBN numbers.
Norm Radder wrote:Can you copy the contents of the command prompt window that shows the problems you are talking about?
Be sure to add some comments to the output to show where the output wasn't expected.
For example:
<<<< This should be ....
Maybe I have very big feet.Enter number of toes:
93 742 Evergreen Terrace Springield
Enter address please:
Norm Radder wrote:Is there anything to print in the new instance of the AddBook class's print method?
Add a print statement to the print() method that prints out the size of the list that is to be printed.
If the list is empty, the loop won't iterate. If the loop doesn't execute, the print statement won't be executed. But you already knew that because nothing was printed.it still didn't print anything.
Carey Brown wrote:I'm guessing that this print method isn't even being called because it's not a method inside AddBook class.
Norm Radder wrote:
If the list is empty, the loop won't iterate. If the loop doesn't execute, the print statement won't be executed. But you already knew that because nothing was printed.it still didn't print anything.
Move it outside of the loop.
A first step.books aren't even added to the list.
Norm Radder wrote:
A first step.books aren't even added to the list.
Where are the books supposed to be added? Why isn't that code being executed?
Suppose to be added
Carey Brown wrote:Could you please re-post ALL of the code again. I think the problem lies somewhere other than the snippets we're seeing.
Norm Radder wrote:
Suppose to be added
Is that code being executed? Add a print statement so you can see.
add a print statement where?
Carey Brown wrote:So, your code seems ok, then it is probably how it is being compiled. Make sure all .java files are saved. Remove all .class files. Do a complete re-compile. Try it again.
those hardcoded books should be somewhere else
Norm Radder wrote:
those hardcoded books should be somewhere else
Yes, that looks like the problem. Do you have any ideas about where that code should go so its results are available anywhere else in the program's execution?
Cary Brown wrote:I'm not sure that I like the way you've broken down your classes
Carey Brown wrote:Utility Classes, a general guideline:
Made up entirely of static methods. Have no knowledge of the application's business logic. Make no calls to the application specific code. Only makes calls to Java libraries or other utility classes. Ideally written in a portable manner so that it would be portable to another application.
If you find yourself bending these rules then perhaps you really aren't dealing with a clean utility situation.
Kevin O'Sullivan wrote:Would a login class that takes a user name and password be considered a good candidate for a utility class ?
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
|