Resource Crafting Simulation

Verified

Added on  2019/09/30

|6
|2073
|332
Project
AI Summary
This assignment involves creating a Java program that simulates the crafting of various items in a game. Students must design a system using inheritance and polymorphism to represent different types of resources (weapons, metals, trees, etc.), each with properties like name, quantity, and damage (for weapons). The program should handle resource consumption during crafting, throwing exceptions for insufficient resources or incorrect material types. Specific crafting recipes are defined, and the program must support saving and loading resources from disk. Advanced features include finding the best craftable weapon given a set of resources using varargs. The assignment includes a TestDriver for verification and requires documentation (inheritance diagram, testing outline, Javadoc comments).
Document Page
This program simulates the crafting of various items in games. That is given a number of different
resources you can consume them and create a new item. For example if you have wood and steel
you can craft a sword. For the sake of the assignment we consider all these things types of
resources.
We are going to simulate this by having a different type of object to represent each type of item along
with the number of items. Each object will represent zero to many items of that type. We also have
categories of resources such as Weapons, Metals, Trees. For example Sword is a type of Weapon
which in turn is a type of Resource. Crafting may require something specific such as Wood and Steel
or it might require something of the same time. Eg Wood and Metal (eg can be Iron or Steel).
Consequently, you must take this into account when you build your crafting table.
Your basic approach is to have an Crafting Table Object which has a seperate method to represent
each type of conversion. For example if you were to Craft a Sword you would call Craft with your
Sword object followed by the ingredients in this case Iron and Wood. As long as you have more than
zero of both the ingredients Iron would be consumed and wood would be consumed and the number
of swords increase by one.
Outline
Obviously there is a inheritance involved in this. Your assignment must follow the following rules
Everything that can be crafted or used in crafting must be a resource
There are Weapon resources which are Anduril, Javelin's, Dagger's,
EnchantedPoleArm's and Swords
There are Metal resources which are Steel and Iron
There are Tree resources such as Oak.
All other resources are types of Resources and they are Dirt, Sand, Seed, Water and
Wood. Metal, Tree and Weapon are also types of resources
Table (crafting Table) is also a type of Resource.
All resources have a name
All resources should have a number on hand.
There should be 21 classes in your implementation they will have at least (in addition
to those below) anduril (a legendary weapon), dirt, dagger, enchantedpolearm, iron,
javelin, metal, oak, resource, sand, seed, steel, sword, tree, water, weapon and wood.
Each resource should be able to return its name and number of resources of that
type
Each resource should have a method to increase the number of resources and
another to decrease the number of resources. If you are out and try to use one it
should throw an resource exhausted exception
There are three types of exceptions that can be thrown in this program
o ResourceExhausted. You attempted to consume a resource that had none
available.
o ResourceNotEnchanted. You attempted to use a metal that wasn't enchanted
where it was necessary.
Every resource should be able to return true or false if the number of resources are
zero.
Weapons resources should have a min damage and max damage variable
Every resource should have constructors for number of resources
Metals can be enchanted or not enchanted.
All variables and methods should have the appropriate visibility
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
All resources should be able to be written to disk via a method call [ boolean
saveToDisk(filename)] return true if successful.
All resources should have a static method called [Resource readFromDisk(filename)]
which will read a resource from the disk and return it to the caller
Anduril (a legendary weapon) can only exist once so the increaseResource method
can only increase to once. Further calls will not consume anymore resources and
won't increase the weapon to more than one. The Anduril class should handle this
internally.
There should be a class Table (itself a Resource) and ResourceExhausted and
ResourceNotEnchanted Exception class the rest of the classes should be various
resources.
If you attempt to craft an item and any of your ingredients are out (eg number is
zero) the method should throw a ResourceExhausted Exception.
Crafting should be done via a crafting table. The crafting table should have methods that
accept parameters to represent the different crafting recipes. The first parameter being the item
being crafted the rest of the parameters being the ingredients.
The following crafting recipes should be supported
1. sword from iron and wood
2. table from iron, wood, steel and sand
3. dagger from steel
4. wood from tree
5. oak from dirt, seed and water
6. enchantedPoleArm from any metal and sword (but only if the metal is enchanted)
7. Anduril from an EnchantedPoleArm, sand, Seed and Steel
8. Javelin from wood
Requirements
Here are a list of requirements for your assignment.
TestDriver class must work. This is designed to use your code.
You must use inheritance where appropriate
Push as much code up the inheritance structure as possible.
You must use abstract where appropriate
You should write some testing to make sure your assignment works. You don't need
to use junit however, whatever you write should do reasonable job of making sure
your assignment works.
Only import the needed classes in each class
Create a Jpg image of your inheritance diagram called inheritance.jpg make sure its
included in the project a txt file with your testing outline called testing.txt
Class javadoc, Method javadoc, Instance javadoc and method body commenting
21 classes should be included in your workspace. Don't panic quite a few of them are
only a few lines of code.
Document Page
Whatever you submit it should be compilable and runnable even if it doesn't do
everything that is required.
Suggested Order
This is a suggested approach to doing your assignment.
Create the packages (base package of unisa.pf.assign02. for the non resource
classes, then a resources
unisa.pf.assign02.resources package for all resources).
Draw up the inheritance structure using this document and supplied code to give you
clues.
Create the missing files and get it to compile (even with empty classes).
At each step think about testing and note down cases which could break your
program/methods
Get the code commented and tested
Write missing methods so that the TestDriver class will compile.
Get the code commented and tested
Testing
You are to write a test outline of what you would test and how you would test it in your program. It is
not necessary to code this just include a textfile (testing.txt). You should put in sections on each class
and under each class each method and the test cases you would test. You do not need to do junit
testing for this assignment (I think you have enough to do without writing all that).
Supplied Code
I have supplied you with a testDriver. You must use this code and you should also fully comment the
code. I have also added the start of the Crafting Table. You will need to add code to this and create
the remaining classes.
Final Part
A perfect solution up to here will get you a Distinction. To get a HD you need to attempt the following
section. My suggestion is get everthing else perfect and then do this bit last don't try it until everything
else is done. Using varargs implement a method (findBestCraftableWeapon with varargs that will
allow the caller to call with any combination of Objects find out what is the best weapon that could be
crafted. The best weapon is defined as the most possible damage it can make. This is correct, we
haven't spoken about varargs. this is a test of your ability to research a new language feature and use
it.
Hints.
Implement a private method to help you search through the arg list for a resource
The simplest (not the quickest) way to look for a resource type is by saying
if (args[0].getName().equals("Wood")) {
System.out.println("You've got wood");
}
Document Page
or
You can use exceptions
15 marks
TestDriver Output
Here is the output from my testing program. This is not an exhaustive test and we will run a different
testing program over your assignment.
Testing out toStrings
*********************
Should be {Dirt number Remaining=2}
{Dirt number Remaining=2}
Should be {Iron Metal, number Remaining=1 enchanted=false}
{Iron Metal, number Remaining=1 enchanted=false}
Should be {Sand number Remaining=2}
{Sand number Remaining=2}
Should be {Seed number Remaining=2}
{Seed number Remaining=2}
Should be {Steel Metal, number Remaining=2 enchanted=false}
{Steel Metal, number Remaining=2 enchanted=false}
Should be {Sword Weapon, number Remaining 2 damageMin=8.0, damageMax=15.0}
{Sword Weapon, number Remaining 2 damageMin=8.0, damageMax=15.0}
Should be {Oak Tree number Remaining=2}
{Oak Tree number Remaining=2}
Should be {Wood number Remaining=3}
{Wood number Remaining=3}
Should be {Dagger Weapon, number Remaining 2 damageMin=2.0, damageMax=5.0}
{Dagger Weapon, number Remaining 2 damageMin=2.0, damageMax=5.0}
Should be {EnchangedPoleArm Weapon, number Remaining 2 damageMin=20.0, damageMax=50.0}
{EnchangedPoleArm Weapon, number Remaining 2 damageMin=20.0, damageMax=50.0}
Should be {Water number Remaining=2}
{Water number Remaining=2}
Should be {Anduril Weapon, number Remaining 2 damageMin=30.0, damageMax=80.0}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
{Anduril Weapon, number Remaining 2 damageMin=30.0, damageMax=80.0}
Should be {Javelin Weapon, number Remaining 2 damageMin=5.0, damageMax=10.0}
{Javelin Weapon, number Remaining 2 damageMin=5.0, damageMax=10.0}
Testing out Crafting
********************
Crafting New Sword Failed Resource Exhausted
Should crash on the second one because not enough resources
Crafting New Table Failed Resource Exhausted
Crafting New PoleArm Failed Resource Exhausted
Crafting New PoleArm Failed Resource Exhausted
Testing Get Description
**************************
1 Needed For Trees
2 Not Great Near The Ocean
3 Hot in the Sun
4 One Day a Mighty Tree
5 Cold Hard Steel
6 Preferred Weapon of Poorer Warriors
7 Nice for Furniture
8 Processed Tree
9 Preferred Weapon of Thieves
10 Magical Enchanted Pole Arm
11 Essence of Life
12 One Sword to Rule Them All
13 Preferred Weapon Of Kids at High School Sports Days
Testing out Random Methods
**************************
Check which weapon is better should say true->true
Check how many daggers are in the bag, should be 0 ->0
Daggers Name >Dagger
Check how many daggers are in the bag, should now be 2 ->2
Swords Available (Should be false)-> false
Swords Available (Should be true)-> true
Sword Min Damage (Should be 8)->8.0
Sword Max Damage (Should be 15)->15.0
Should be Oak->Oak
Should be Iron->Iron Metal, number Remaining=0 enchanted=true
Document Page
Should be Enchanted (True)->true
Should not be Enchanted (False)->false
Should be (Sand number Remaining=0)->Sand number Remaining=0
Testing out File IO
*******************
Next time lines are identical
Sword Weapon, number Remaining 924 damageMin=8.0, damageMax=15.0
Sword Weapon, number Remaining 924 damageMin=8.0, damageMax=15.0
Testing out Advanced Features
*****************************
Testing Advanced Method
Should be Javelin ->Javelin
Should be Dagger ->Dagger
Should be Sword ->Sword
Should be Javelin ->Javelin
Should be None ->none
Should be Dagger (Not EnchantedPoleArm Because the metal is not Enchanted) ->Dagger
Should be Enchanted Pole Arm (using enchanted steel)->EnchantedPoleArm
Should be Enchanted Pole Arm (using enchanted iron) ->EnchantedPoleArm
chevron_up_icon
1 out of 6
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]