Question
Asked by:
mgfloyd71
mgfloyd71
Rating : No Rating
Questions Asked: 2
Tutorials Posted: 0
 

$10.00 Create a Book class that stores book information

Q:
Create a Book class that stores book information. Your book class will store book title, author’s first name, author’s last name, book ISBN-10 number, and publisher, and price. Ensure you have created appropriate constructor(s) that will allow your test application to construct objects of type Book.

You can decide how to obtain the information used for each Book object you create. Each book’s information can be entered through the keyboard, read in from a file, or constructed by using hard coded values in your test application.

Create a test application that creates several objects of type Book class and adds each Book object to an ArrayList. Do not store your book information as a String and add this String into your ArrayList. You should store Book objects that encapsulate your book information and store these in your ArrayList:

//Creates arrayList to store book objects
ArrayList<Book> bookList = new ArrayList<Book>();

Your test application should then do the following:

Iterate through all Books in the ArrayList and print the information out in readable form.
Print the total number of books stored.
Prompt you for an index and print the book information stored in the index.
Hint: You may want to look into overriding toString() method to provide a readable string representation of Book object.











 
Attachments:
sample output.gif (33K)
sample output2.gif (9K)


   
   
   
   
 
Available Tutorials to this Question
Posted by:
modulo51
modulo51
Rating (110): A-
Questions Asked: 1
Tutorials Posted: 353, earned $2,117.64
 

$15.00 Java: BookInventory, Scanner input, ArrayList<Book>, NetBeans folder, UseNotes, consoleOutput

  • This tutorial was purchased 6 times and rated A+ by students like you.
  • Posted on Aug 04, 2009 at 11:38:38PM
A:
Preview: ... <br> }<br><br> String getPublisher() {<br> return new String(this.publisher);<br> }<br><br> double getPrice() {<br> return this.price;<br> }<br><br> // set methods:<br> void setTitle(String titleIn) {<br> this.title = titleIn;<br> }<br><br> void setAuthorFirstName(String authorFirstNameIn) {<br> this.authorFirstName = authorFirstNameIn;<br> }<br><br> void setAuthorLastName(String authorLastNameIn) {<br> this.authorLastName = authorLastNameIn;<br> }<br><br> void setISBN(String ISBNin) {<br> this.ISBN = ISBNin;<br> }<br><br> void setPublisher(String publisherIn) {<br> this.publisher = publisherIn;<br> }<br><br> void setPrice(double priceIn) {<br> this.price = priceIn;<br> }<br><br> public static void readInventoryFile() {<br><br> // open file:<br> Scanner inStream;<br> try {<br> // input file:<br> inStream =<br> new Scanner(new File(inFileName));<br><br> // read in book data:<br> while (inStream.hasNext()) {<br><br> Book yep = new Book(<br> inStream.nextLine().trim(), // title<br> inStream.nextLine().trim(), // fisst name<br> inStream.nextLine().trim(), // last name<br> inStream.nextLine().trim(), // publisher<br> inStream.nextLine().trim(), // ISMB<br> Double.parseDouble(inStream.nextLine().trim())); // price<br><br> // this displays each book as it's being read in:<br>// System.out.println(yep.toString());<br><br> bookList.add(yep);<br><br> // tead the empty line separating books in the file:<br> // this black line must follow each block of book into<br> // there must NOT be an empty line at the top of the file!<br> ...

The full tutorial is about 3044 words long plus attachments.

Attachments:
BookInventoryPrnScr.JPG (44K) (Preview)
BookInventoryConsole.txt (2K) (Preview)
BookInventoryUseNotes.txt (9K) (Preview)
BookInventoryZipped.zip (40K)
Posted by:
 

$10.00 Java code with constructors, array list, DataInputStream and all specified constraints

  • This tutorial hasn't been purchased yet.
  • Posted on Aug 07, 2009 at 09:32:35PM
A:
Preview: ... int("\\n Price: "+price);<br> } <br> }<br> <br> class bookInfo<br> {<br> public static void main (String[] args)throws IOException <br> {<br> String fname,lname,code,pub,tit;<br> float price;<br> <br> book[] b1=new book[20]; // object to receive values from user<br> book[] b2=new book[20]; // object to display values from array list<br> <br> int bookno,booksize,bookindex; // booksize total no. of books stored<br> // bookno used for index<br> // bookindex used to get index to search for a book<br> <br> String ch; // gets decision from user to continue<br> <br> ArrayList<book> booklst=new ArrayList<book>(); // stores book information<br> <br> DataInputStream in=new DataInputStream(System.in);<br> <br> booksize=0; // in ...

The full tutorial is about 340 words long plus attachments.

Attachments:
bookInfo.java (3K) (Preview)
RESULT.JPG (31K) (Preview)
Posted by:
modulo51
modulo51
Rating (110): A-
Questions Asked: 1
Tutorials Posted: 353, earned $2,117.64
 

$7.00 Simplified single source file only...for kipkemboi...

  • This tutorial was purchased 1 time and rated A+ by students like you.
  • Posted on Aug. 08, 2009 at 12:52:34AM
A:
Preview: ... "Invalid choice, please try again.");<br> } else {<br> return choice;<br> }<br><br> } catch (Exception e) {<br><br> System.out.println(<br> "Input error: " + e.toString());<br> }<br> }<br> }<br><br> public static void readInventoryFile() {<br><br> // open file and input data:<br> Scanner inStream;<br> // input file:<br> try {<br> inStream =<br> new Scanner(new File(inFileName));<br><br> // read in book data:<br> while (inStream.hasNext()) {<br><br> Book2 yep = new Book2(<br> inStream.nextLine().trim(), // title<br> inStream.nextLine().trim(), // fisst name<br> inStream.nextLine().trim(), // last name<br> inStream.nextLine().trim(), // publisher<br> inStream.nextLine().trim(), // ISMB<br> Double.parseDouble(inStream.nextLine().trim())); // price<br><br> bookList.add(yep);<br><br> // tead the empty line separating books in the file:<br> // this black line must follow each block of book into<br> / ...

The full tutorial is about 2275 words long plus attachments.

Attachments:
Book2.java (5K) (Preview)
BookFile.txt (0K) (Preview)
consoleOutput.JPG (101K) (Preview)
consoleOutput.txt (1K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty