1 Input
The program reads data from one file, items-0x.txt. Each line in this file represents one item. The first item on every line denotes the Item typethe remainder of the line varies by item type.
Tool Pickaxe Diamond 100 1 Fortune 5
Tool Shovel Gold 20 3 Unbreaking 2
Tool Pickaxe Diamond 100 1 Fortune 5
Potion Speed-II-Potion Spd*2 1
Food Tomato Hunger-10 2
Disposable PotatoCamera ImageQuality-97% 5
Disposable PotatoCamera ImageQuality-97% 5
Tool Axe Stone 10 2 Unbreaking 2
Armour Boots Diamond 100 10 Protection 3 lightning
Armor Boots Diamond 100 10 FeatherFalling 4 lightning
Each Item type is denoted by a keyword:
Tool
indicates aTool
object.Armour
andArmor
indicate anArmour
object.Food
,Potion
, andDisposable
indicate aConsumable
object.
After the leading keywords, each line has a distinct structure:
- The remainder of a
Tool
line containsin ordera name, material, durability, speed, modifier, and modifier level.Tool
Items are notstackable
. - The remainder of a
Armour
line containsin ordera name, material, durability, defense, modifier, modifier level, and element.Armour
Items are notstackable
. - The remainder of a
Consumable
line containsin ordera name, effect, and # uses.Consumable
Items arestackable
.
In each of the above classes, you will need to:
- Set the stackable attributei.e.,
super.stackable
. The attribute,stackable
, is a private data member ofItem
. - Set the name attributei.e.,
super.name
. The attribute,name
, is a protected data member ofItem
.
2 Output
If the program is run with the first provided input file, items-01.txt, the following output should be generated:
Processing Log:
(S) Pickaxe
(S) Shovel
(S) Pickaxe
(S) Speed-II-Potion
(S) Tomato
(S) PotatoCamera
(S) PotatoCamera
(S) Axe
(S) Boots
(S) Boots
Player Storage Summary:
-Used 90% of 10 slots
Nme: Pickaxe
Dur: 100
Spd: 1
Mtl: Diamond
Mdr: Fortune (Lvl 5)
Nme: Shovel
Dur: 20
Spd: 3
Mtl: Gold
Mdr: Unbreaking (Lvl 2)
Nme: Pickaxe
Dur: 100
Spd: 1
Mtl: Diamond
Mdr: Fortune (Lvl 5)
Nme: Speed-II-Potion
Eft: Spd*2
Use: 1
Qty: 1
Nme: Tomato
Eft: Hunger-10
Use: 2
Qty: 1
Nme: PotatoCamera
Eft: ImageQuality-97%
Use: 5
Qty: 2
Nme: Axe
Dur: 10
Spd: 2
Mtl: Stone
Mdr: Unbreaking (Lvl 2)
Nme: Boots
Dur: 100
Def: 10
Mtl: Diamond
Mdr: Protection (Lvl 3)
Emt: lightning
Nme: Boots
Dur: 100
Def: 10
Mtl: Diamond
Mdr: FeatherFalling (Lvl 4)
Emt: lightning
Your outputincluding labels and spacingmust match the expected output.
3 Your Tasks
The key abstractions employed in this program are Inventory
, Item
, ItemStack
, Tool
, Armour
, and Consumable
.
Do not change the packages. The package must remain package edu.odu.cs.cs330.items;
for Tool, Armour, and Consumable. Changing the package is an automatic fail. Is this strict? Absolutely. However, I am explicitly instructing you to use this package.
You have a few tasks to complete. First, start with the Armour and Consumable ADTs:
- Complete the Default Constructor for each class.
- Complete the Copy Constructor for each class.
- Complete the
clone
method for each class. - Complete the
read
method in each class. - Complete the
toString
method in each class.
The first few tasks should be familiarthey were your tasks in . You will then need to complete:
Armour.equals
Armour.hashCode
Consumable.equals
Consumable.hashCode
The rules for computing hash codes and checking for equivalence are listed the Javadoc comments (i.e., in comments before the function).
Adding the Tool Class
Your final set of tasks involve completing the Tool
class.
- Complete the Tool Constructor.
- Complete the Tool Copy Constructor.
- Complete the Tool
clone
method. - Complete the Tool
read
method. - Complete the Tool
toString
method. - Complete the Tool
equals
method. - Complete the Tool
hashCode
method.