This is an open note exam. You are welcome to consult any of the examples I have posted on the course web site and copy small snippets of code from them. All work on this exam should be your own individual work - you may not collaborate with other students on this exam.
Many video games and board games feature the concept of crafting, which allows players to use some of the items in their inventory to make other items. Some examples include
2 wheat, 3 stone and 1 settlement = 1 city
1 Nuka-Cola, 1 Tin Can, 1 Turpentine, 1 Abraxo Cleaner = 1 Nuka Grenade
In this exam problem you will create a simple database application to implement crafting. The database you will work with has two tables, a recipe table and an inventory table. The recipe table contains crafting recipes, and has this structure:
Column | Description |
---|---|
item | Item number of item to craft |
ingredient | Item number of required ingredient |
quantity | How much of this item is required |
A recipe consists of one or more rows of ingredients for making a particular item. For example, the table may contain a recipe for constructing item 11 that consists of three rows:
item | ingredient | quantity |
---|---|---|
11 | 1 | 1 |
11 | 2 | 2 |
11 | 4 | 1 |
This tells us that to craft item 11 a player needs to have 1 item #1, 2 item #2 and 1 item #4 in their inventory.
The inventory contains inventory information for all of the players and has this structure:
Column | Description |
---|---|
player | id number of a player |
item | id number of an item |
quantity | How much of this item the player has |
Your job is to a construct a simple GUI application that works with the database to manage crafting. The GUI will allow a user to enter a combination of a player number and an item number. The user clicks the Craft button to try to craft the given item. If the player has all of the required items in their inventory, the program will remove the ingredient items from the player's inventory and then insert 1 unit of the crafted item into their inventory.
If the program determines that the player in question does not have all of the ingredients to craft the given item, the program will display a message saying that the item can not be crafted.
Start by clicking the button at the top of this page to download the starter project for this exam.
Start up the MySQL workbench and make a new, empty schema with the name 'craft'. Inside the starter project folder you will find a database folder. Use the data import tools in the MySQL workbench to import these database files for the craft database.
In the starter project I have already provided some code for you, and I have set up the GUI for the application. You will need to link the GUI elements in Scene Builder to the appropriate variables and action methods in the controller class.
I have provided code for the following class
public class Requirement { private int item; private int quantity; public Requirement(int item,int quantity) { this.item = item; this.quantity = quantity; } public int getItem() { return item; } public int getQuantity() { return quantity; } }
I have also set up a DAO class and put these methods in it:
// Fetch the list of required items for the recipe to make the given item public List<Requirement> getRequirements(int item) {} // Return true if the given player has all of the required items in their inventory public boolean hasRequirements(int player,List<Requirement> required) {} // Remove the required items from the player's inventory and add one unit of the product public void craft(int player,List<Requirement> ingredients,int product) {}
Your controller code should call these DAO methods to implement the logic for the crafting button.
Your job will be to write the necessary code in the controller class and in the DAO class to get everything working.