OOP.java

  

complete the Armour and Consumable classes.

1.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

Potion Speed-II-Potion Spd*2 1

Food Tomato Hunger-10 2

Tool Axe Stone 10 2 Unbreaking 2

Armour Boots Diamond 100 10 Protection 3 lightning

Each Item type is denoted by a keyword:

  • Tool indicates      a Tool object.
  • Armour and Armor indicate      an Armour object.
  • Food, Potion,      and Disposable indicate a Consumable object.

After the leading keywords, each line has a distinct structure:

1. The remainder of a Tool line containsin ordera name, material, durability, speed, enchantment, and enchantment level. Tool Items are not stackable.

2. The remainder of a Armour line containsin ordera name, material, durability, defense, enchantment, enchantment level, and element. Armour Items are not stackable.

3. The remainder of a Consumable line containsin ordera name, effect, and # uses. Consumable Items are stackable.

1.2 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

Potion Speed-II-Potion Spd*2 1

Food Tomato Hunger-10 2

Tool Axe Stone 10 2 Unbreaking 2

Armour Boots Diamond 100 10 Protection 3 lightning

Each Item type is denoted by a keyword:

  • Tool indicates      a Tool object.
  • Armour and Armor indicate      an Armour object.
  • Food, Potion,      and Disposable indicate a Consumable object.

After the leading keywords, each line has a distinct structure:

1. The remainder of a Tool line containsin ordera name, material, durability, speed, modifier, and modifier level. Tool Items are not stackable.

2. The remainder of a Armour line containsin ordera name, material, durability, defense, modifier, modifier level, and element. Armour Items are not stackable.

3. The remainder of a Consumable line containsin ordera name, effect, and # uses. Consumable Items are stackable.

In each of the above classes, you will need to:

1. Set the stackable attributei.e., super.stackable. The attribute, stackable, is a private data member of Item.

2. Set the name attributei.e., super.name. The attribute, name, is a protected data member of Item.

1.3 Output

If the program is run with the first provided input file, items-01.txt, the following output should be generated:

Processing Log:

(S) Speed-II-Potion

(S) Tomato

(S) PotatoCamera

(S) PotatoCamera

(S) Boots

(S) Boots

Player Storage Summary:

-Used 50% of 10 slots

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: 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 Tasks

The key abstractions employed in this program are Inventory Item, ItemStack, Tool, Armour, and Consumable.

Your task is to finish the Armour and Consumable ADTs:

  1. Complete the Default Constructor for each class.
  2. Complete the Copy Constructor for each class.
  3. Complete the clone method for each class.
  4. Complete the read method in each class.
  5. Complete the toString method in each class.

Note that I have provided stubs for each of these functions (i.e., the code will compile). However, until you complete these functions, the code will not generate meaningful output

2 Compiling Java

The easiest way to compile this assignment is to use the ./gradlew command on one of our Linux servers. After that, you will have a number of options for executing the code.

Compiling and Running the Java Program

If the sample data above is kept in items-01.txt, to run this program, type:

./gradlew jar
java -jar build/libs/Storage.jar src/main/resources/items-01.txt 10

or

./gradlew run

Compiling and Running the Tests

You should probably run the tests on a Linux machine You can compile and run the test drivers (TestArmour and TestConsumable) with

./gradlew test

If you implemented everything in Armour and Consumable correctly you will see:

 testClone PASSED
 testCopyConstructor PASSED
 testDefaultConstructor PASSED
 testRead PASSED
testToString PASSED
testClone PASSED
 testCopyConstructor PASSED
 testDefaultConstructor PASSED
 testRead PASSED
testToString PASSED

If you see FAILED you must revisit revisit the corresponding function(s). There is a mistake in your code.

You may need to run

./gradlew clean test

to force a full recompile after making small updates.

Submitting

The package must remain the same; for Armour and Consumable. Changing the package is an automatic fail

Files to Submit:

  • Armour.javai.e., your version of the Armour ADT.
  • Consumable.javai.e., your version of the      Consumable ADT.