• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Java application that will allow you to store details of your favourite books. Help assignment fail

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am hoping someone can help. I am new to Java so apologies if i have made a mess of the code.

I have an assignment due and I cant get the program to work.

The individual parts work but not together. info and code below:
1.menu system
2.Ask the user how many books their application should store
3.Add book details
4.Display details of a book and Display all the Books
5.End application
Java program must have the following:
• A Book class with appropriate properties and methods (including get and set)
• Appropriate use of methods for the menu system
• Appropriate use of loops
• Appropriate use of a toString method in the Book class
• Appropriate use of validation of user entry
• Appropriate use of comments
• An application class that will run the menu described in the scenario

 
Bartender
Posts: 7823
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gerald hart wrote:I cant get the program to work.


This doesn't help us help you. What exactly doesn't work?
Are you getting error messages? If so, post the *complete* error message.
Are you not getting the right results? If so, what input are you giving it.
 
gerald hart
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carey thanks for getting back to me.

one error on the book class is saying that the method is never used. not sure how to fix it.
all i want it to do is ask user how many books to store, user inputs details and the application stores then display all books and book details.
this is what I am getting!! hope you can help

console readout:
How many books would you like to store?: 2
Enter the book title you want to remove: lehane
Amended book titles-nothing coming up

The Title of the Book:    null
The Author of the Book:   null
The Year of publish:      0
The name of the Publisher: null
The details of the book object is null

Enter the title of the Book 1: code
Enter the author of the Book 1: michael
Enter the Year of published 1:1988
Enter the name of the publisher1:obrian

then it displays book details:
Book Details 1:  

The Title of the Book:     code
The Author of the Book:    michael
The Year of publish:      1988
The name of the Publisher:
Book Details 2:  
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's very important that you post the exact code you are working on.  There are no unused methods in the code you posted.

There are a lot of things I could comment on but until we have the correct code, it would probably be a waste of time.
 
Carey Brown
Bartender
Posts: 7823
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After a quick read of your code I notice a couple of problems with your use of Scanner. You have other issues too, but this will trip you up.
On line 76 you get an int, this has a side effect of leaving a pending new-line in the queue waiting to be processed. Then on line 79 you get nextLine and this sees, "ah, ha! I've got a new-line", before you've even typed anything, because it was left over from nextInt. The result is 'publlsher' is an empty String. In order to fix this you need to flush the pending new-line immediately after you call nextInt(). You do this by calling nextLine() and ignoring the returned String.

The other trap you've fallen into is that a PROJECT should only ever open a single Scanner using System.in ONCE. You are opening it twice. The best way to enforce this is to make the Scanner a constant. As a public static constant it will be available to all classes and methods in your project.
Now replace all in.nextLine() with KEYBOARD.nextLine().
 
Marshal
Posts: 72098
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would prefer to use a utility class for keyboard input. That class can hide the Scanner instance and also take care of that gotcha about nextLine(). You may not have the time to write a utility class, but if you search my posts for “Scanner utility class” you will eventually find enough parts to assemble a complete class (an one serious error).
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, Carey Brown has written a KeyboardUtility (see his sig line) and I have written one called Inputer.
 
Carey Brown
Bartender
Posts: 7823
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI
I have also posted a Keyboard Scanner Utility Class, the link is in my signature at the bottom of this post.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic