I am new here and didn't do well on a problem in school and was wondering what i did wrong!
PROBLEM: Create a Book class that stores book information. Your Book class will store the following:
•book title
•author’s first name
•author’s last name
•book ISBN-10 number
•publisher
•price
Create a test application that creates several objects of type Book class and adds each book to an ArrayList. 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
CODE /w errors (can't figure out why they error):
import java.util.*;
public class book
{ public String title;
public String authorname;
public String authorlast;
public String ISBN;
public String publisher;
public String price;
public static int count = 0; //number books created
//initial book, add 1 to static count
public book (String first, String last, String ISBN, String publisher, String price)
{
title = title;
authorname = authorname;
authorlast = authorlast;
ISBN = ISBN;
publisher = publisher;
price = price;
++ count;
system.out.printf( "%s, %s Title: %s Price: %s ISBN: %s Publisher: %s; count = %d\n", authorname, authorlast, title, price, ISBN, publisher, count );
}
public String toString() {
{
return String.format( "%s, %s Title: %s Price: %s ISBN: %s Publisher: %s count", authorname, authorlast, title, price, ISBN, publisher, count );
}
}
public class booktest
{
public static void main (String[] args)
{
System.out.printf( "books before instantiation: %d\n", book.getCount() );
ArrayList <book> bookArrayList = new ArrayList <book> ();
book book1 = new book("Frog", Erik, Anderson, "221667691169", "Leapfrog productions", "69.69"
book book2 = new book("Frog2", Erik, Anderson, "221667691170", "Leapfrog productions", "68.68"
book book3 = new book("Frog3", Erik, Anderson, "221667691171", "Leapfrog productions", "77.77"
System.out.println();
for(book book : bookArrayList)
System.out.println( book.title + " " +
System.out.println( book.authorname + " " +
System.out.println( book.authorlast + " " +
System.out.println( book.ISBN + " " +
System.out.println( book.publisher + " " +
System.out.println( book.price + " " +
book.getCount() );
System.out.println();
System.out.println("Total number of books = " + bookArrayList.size());
}
I am missing something i just don't know what as i am new to this!
Yes the assignment was due Feb 27, 2011 thats why i am asking now because i didn't do well on it! Also any help or assistance be appreciated!