Class Store

Object
  extended by Store

public class Store
extends Object

Store is the main class for a book store.


Constructor Summary
Store()
          Store default constructor initializes all its instance fields.
 
Method Summary
 void addBook(Book aBook)
           
 void fillInventory(String filename)
          fillInventory loads the inventory from a named, formatted file.
 double getMarkup()
          getMarkup returns the cost multiplier for price production.
static void main(String[] args)
          main method
 void offerSearch()
          offerSearch offers the user a way to search by title, author, or media.
 void printInventory()
          print the entire store inventory to standard output.
 Book produceBook(String line)
          produceBook consumes a line of text and produces a Book instance.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Store

public Store()
Store default constructor initializes all its instance fields.

Method Detail

addBook

public void addBook(Book aBook)
Parameters:
aBook - the book to add to the store inventory

fillInventory

public void fillInventory(String filename)
                   throws java.io.FileNotFoundException
fillInventory loads the inventory from a named, formatted file.

Parameters:
filename - source of the inventory content descriptions.
Throws:
java.io.FileNotFoundException - if filename is invalid.

produceBook

public Book produceBook(String line)
produceBook consumes a line of text and produces a Book instance. produceBook expects the text to have specific tilde-delimited fields.

Parameters:
line - of text containing a single inventory item description
Returns:
a valid Book instance or null if code detected errors in text

Expected File Format: A tilde (~) is the field delimiter for the text.

TITLE~AUTHOR~COST[~media format information]

The TITLE and AUTHOR are required, standard strings.

The COST is in whole US cents. For example, 4993 means a cost of $49.93. A zero COST indicates that it cost the store nothing; it is not a price.

The last field, media format information is optional and may be absent. The media format information depends on the particular kind of book.

 (empty)     means a paperback book medium.
 cloth       means a hardcover book medium.
 leather     means a hardcover book medium.
 ...://...   means an electronic book medium (from the URI format).
 (integer)   means an audio-book medium; the value is the number of discs.
 

Example:

 Ulysses~James Joyce~895
 Ulysses~James Joyce~3195~leather
 Ulysses~James Joyce~2395~cloth
 Ulysses~James Joyce~0~http://www.amazon.com
 Sometimes a Great Notion~Ken Kesey~1295~3
 

getMarkup

public double getMarkup()
getMarkup returns the cost multiplier for price production.

Returns:
the cost multiplier for price production.

printInventory

public void printInventory()
print the entire store inventory to standard output.


offerSearch

public void offerSearch()
offerSearch offers the user a way to search by title, author, or media. offerSearch enters an open-ended user interaction loop to let a person enter search queries and possibly ask to buy a book.

Based on the search code entered ('t', 'a', or 'm'), the search scans the inventory for values matching an entered phrase.

The matching process is case-insensitive. The user may enter a blank line or a 'q' to quit.

If there are any matches, the user has the chance to choose which one to buy.


main

public static void main(String[] args)
                 throws java.io.FileNotFoundException
main method

Parameters:
args - must contain the name of the file that holds the inventory.
Throws:
java.io.FileNotFoundException