Deals with a file containing information about items: CDs, DVDs, and Games. An example of such a file is here. Note that items have attributes. Each attribute is described by a line, name of the attribute, space, value of the attribute. Item descriptions are separated by empty lines. The order of the items in the file is up to you. The first line of an item description gives the attribute 'type' and its value, say, 'CD'.
The second line of an item description gives the attribute 'uniqueId' whose value is a string of 10 alphanumeric characters, for instance, 'B00000240G'
In addition to the type and the uniqueId, here are the attributes of an item:
For a CD
title - A string, the title of this item
person - A string, the name of the artist who made the CD
cost - A double, the cost of this CD
haveIt - A string, "yes" or "no" depending if I have it or not
comment - A string, something we want to say about the item. It should be a single line
For a DVD
title - A string, the title of this item
person - A string, the name of the director who directed the DVD
cost - A double, the cost of this DVD
haveIt - A string, "yes" or "no" depending if I have it or not
comment - A string, something we want to say about the item. It should be a single line.
date - A string representing the date the DVD went on sale
For a Game
title - A string, the title of this item
person - A string, the name of the game designer
cost - A double, the cost of this game (but you may choose to store it as a string)
haveIt - A string, "yes" or "no" depending if I have it or not
comment - A string, something we want to say about the item. It should be a single line.
date - A string representing the date the game went on sale
numberOfPlayers - an int, the number of players for this game (but you may choose to
store it as a string).
As you see CDs, DVDs, and games have a lot of attributes in common, so it pays to define an abstract class Item of which they are all subclasses.
Define an abstract class to represent Item. Define concrete classes to represent CD, DVD, Game. Classes should have constructors, access methods for each attribute plus modifiers for each attribute except type and uniqueId. There should also be methods for writing an item to a PrintWriter (or a PrintStream) and for reading it with/out prompt from a Scanner.
When the program starts it loads into memory the items defined in the file items.txt. In this file all uniqueId attibute values are unique. The items in main memory are kept in an itemList variable of type ArrayList- . Your program should in a loop offer the following choices to the user:
Create a new item entry.
/* The new item defined by the user [it must have a unique id] is added to itemList */
Delete an existing item entry
/* The item is identified by its uniqueId and is removed, if there, from itemList */
Update modifiable attributes of an item
/* The item is identified by its uniqueId and the attribute by its name*/
List items
The items are listed in sorted order, CDs first, then DVDs, then Games. Within a kind items are listed alphabetically according to their title.
Terminate. /* The content of itemList is saved to items-new.txt */
We know that we need to be careful when reading from a user the definition of an item, to make sure that the values are reasonable (remember that we know how to deal with exceptions and how to write exception handlers, and how to use things like hasNextInt, hasNextDouble, ...). In this homework you deal with this problem only as time permits. You will receive full credit even if you do not.