CMPSCI 305 Lab 6 Arrays of Objects
Lab 6: Arrays of Objects
Due: 10pm Thursday March 22
Purpose:
In this assignment, you will learn how to use arrays of objects and to
use a file for reading input. You will create arrays where each
element of the array is an object. Accessing this array is very
similar to accessing an array of simple data types.
You will write three classes: Book.java which implements a Book class,
BookList.java which implements a BookList class, and Bookstore.java
which interacts with the user, creates a list of books, and offers
operations over this list. Together these classes will provide part of
the functionality that you would find in a bookstore database
system. Each Book will have three instance variables: a title
(String), an author (String), and a price (double). A BookList will
contain as instance variables: a name (String), the number of books it
stores (int), and an array of Book objects (Book[]).
As your program starts, it will firstly ask the user to give the name
of a file that contains the data for populating the book list. This
file should be a normal text file (fileName.txt) that contains
the information given below, exactly in the order specified:
List Name
Number of books
Book 1 Title
Book 1 Author Name
Book 1 Price
Book 2 Title
Book 2 Author Name
Book 2 Price
.....
Book n Title
Book n Author Name
Book n Price
An example is provided here. As part of this
lab, you must provide another input list in a separate file, named
"myList.txt".
Your program will read the file data and use it to create a BookList
that contains the specified information. It should therefore create a
BookList of the appropriate size, and for each record it reads from
the file, it should create a new Book object and add it to the book
list.
Once it has populated the book list with all the appropriate objects, the program will repeatedly ask the user to:
- Search for a specific book title.
- Search for all the books by a specific author.
- Print the contents of the book list.
- Find the number of books that cost less than a specific price.
A sample execution of the program is given here.
We have provided templates (BookTemplate.java, BookListTemplate.java, BookstoreTemplate.java) for each of the three classes with signatures of all the constructors and methods you should define. You can also
add any helper methods you need for your implementation.
You must implement the appropriate error checking that relate to all
the queries in the book list, and you must communicate to the main
method when a query fails to retrieve any information through
appropriate return values. You may choose whichever values seem
intuitively correct to you -- for example if you can't find a specific
author in the book list, you may return null as the Book[] object.
Extra Credit (15 points): For
extra credit, add the feature of book rating to your system. This
feature will require an additional option in the main menu for rating
a specific book. The book rating should be defined as an extra
instance variable of type int in the Book class. Therefore you must
also provide special functions to get and set this variable, and also
change the other methods of the class in order to manage this extra
information. The rating of each book should initially be the
value -1, which denotes that there is no rating for this item. Allowed
values for the rating should be greater than or equal to zero.Your
program should also include tests to make sure that the user is
actually rating an existing book and that the value is within the
proper bounds (you can define your own upper bound). Whenever you
print some book related information, the rating must be printed
too.
Submission and Grading:
Always include your names, slip days, and a comment at the top of
your file. Here is the template header for all the java files that you will create.
/**
* @author name 1: discussion section time:
* CS account user name:
* Section Unique Number:
* slip days used on this assignment: ??/4
* total slip days used: ??/6
*
* @author name 2: discussion section time:
* CS account user name:
* Section Unique Number:
* slip days used on this assignment: ??/4
* total slip days used: ??/6
*
* On our honor, we followed the pair programming rules of splitting
* keyboard time evenly and 80% or more joint development, and we have
* neither read nor copied code, nor have we shown or given our code to
* others.
*
* @version Date
*
* Extra Credit attempted (Yes/No):
*
* Describe what this program does, including any extra credit attempted.
*
*
*/
Submit your version of Book.java, BookList.java, Bookstore.java and myList.txt using the turnin program . If you need help goto
turnin program help.
Your program should be internally correct (sound logic) and
externally correct (following Java style
guideline).
If you are submitting without a partner, please include your
initial partner and the email correspondence with the instructor or
with the TA in your header.