Skip to content

Practical work repository for the Programming Paradigms course at the National University of La Matanza (@unlam).

License

Notifications You must be signed in to change notification settings

hozlucas28/Java-Practical-Work-2025

Repository files navigation

Java Practical Work [2025]

Repository for the practical work of the Programming Paradigms course
- UNLaM (National University of La Matanza) -

Summary • Features • Installation • Diagrams • Team workflow • Development team
Additional material • License • Acknowledgments

[ Spanish version ]

Preview

(demonstration video)

Summary

This repository contains the practical work for the Programming Paradigms course at the National University of La Matanza (UNLaM). The practical work consists of doing a crafting system in Java and testing it with JUnit 5.

Tip

If you want the read an extensive documentation of each process involved within the system, consult the dedicated documentation page.

Features

  • Architecture planning
  • Code conventions and standards
  • Code documentation using JavaDoc syntax
  • Collections
  • Commits following the Conventional Commits
  • Dedicated documentation page
  • Deployment of releases
  • E2E testing with JUnit 5
  • File reading and interpretation
  • Input control using validations
  • Integration with Prolog
  • Local storage of records
  • Team Workflow planning (branches, tags, and releases)
  • Unit testing with JUnit 5

Installation

  1. Download the latest release of the source code (zip version) to your device.
  2. Install Java and Prolog (check Add swipl to the system PATH option during the installation).
  3. Install Eclipse IDE for Java developers.
  4. Open the downloaded source code with Eclipse IDE.
  5. Then, press right click on Main.java file and select Run As -> Java Application.
  6. That's all, enjoy the crafting system through the interaction with the console.
How can I run all JUnit tests?

If you want to run all JUnit tests, you have to press Right click on the project within Package explorer of Eclipse IDE, and select Run as -> JUnit Test. That's all, Eclipse IDE will start running all the tests.

How can I change the inventory?

To change the items in the inventory, you have to update the inventory.json file with the desired ones.

It's important to follow the same structure as the original ones, and these must be defined inside the recipes.json file.

How can I change the list of available items to craft?

To change the list of available items to craft, you must update the recipes.json file with the new craftable items.

It's important to follow the same structure as the original ones.

Known issues

Issue Solution
Prolog could not find system resources In Eclipse IDE, go to File tab and select Import option. Then, you have to search for Launch configurations, select it and press Next. After that, browse the project directory, select Java-Practical-Work-2025, Main, and PrologServiceTests files and check Overwrite existing launch configurations without warning. option. Finally, press Finish to load your local Prolog instance. If this didn't work, check out the value of each environment variable inside Environment tab in each run configurations of Java-Practical-Work-2025, Main, and PrologServiceTests, as they must aim to your local Prolog directory.

Diagrams

Class diagram
---
config:
  class:
    hideEmptyMembersBox: true

  theme: redux
  look: neo
  layout: elk
---
classDiagram
direction TB

    class Menu {
        -Scanner scanner
        -Inventory inventory
        -ItemsRepository itemsRepository
        -Item itemToCraft
        -int quantityToCraft
        -CraftingSystem craftingSystem
        -PrologService prologService

        -void setItemToCraft()
        +void init()
        -int requestOperation(String item, int quantity)
        -int requestBranch()
        -int requestRecipeToCraft()
        -String requestPrologPath()
        -String requestInventorySavePath()
        -void showCraftableItemsByProlog()
        -void showIngredientsCollection(Collection~List~Ingredient~~ collection, Function~Integer, String~ onEmptyList)
    }

    Menu "1" --o "1" Inventory : Has a reference to
    Menu "1" --o "1" ItemsRepository : Has a reference to
    Menu "1" --o "1" Item : Has
    Menu "1" --o "1" CraftingSystem : Has
    Menu "1" --o "1" PrologService : Has a reference to

    class ItemsRepository {
	    -HashMap~String, Item~ items

	    +HashMap~String, Item~ getItems()
	    +HashMap~String, Item~ getCraftableItems()
	    +Item getItem(String name)
        +static ItemsRepository loadFromJSON(String path)
        +String toString(String itemMarkers[], int lPadding)
    }

    class PrologService {
	    -String baseItemFactName
	    -String ingredientFactName
	    -String itemInInventoryFactName
	    -ItemsRepository itemsRepository
	    -Inventory inventory

        +HashMap~Item, Integer~ craftableItems()
        +void toFile(String path)
        -void toFile(FileWriter fWriter)
        -String toProlog(ItemsRepository itemsRepository)
        -String toProlog(Inventory inventory)
        -String utilityRules()
    }

    class Item {
	    -String name
	    -List~Recipe~ recipes

	    +String getName()
	    +List~Recipe~ getRecipes()
	    +boolean isBase()
    }

    class Recipe {
	    -Item craftingTable
	    -List~Ingredient~ ingredients
	    -int timeToCraftInMilliseconds
	    -int quantityToCraft

	    +Item getCraftingTable()
	    +List~Item~ getIngredients()
	    +int getTimeToCraftInMilliseconds()
	    +int getQuantityToCraft()
	    +List~Item~ getBaseIngredients()
	    +boolean needsCraftingTable()
        +void setCraftingTable(Item craftingTable)
        +void setIngredients(List~Ingredient~ ingredients)
    }

    class CraftedItem {
	    -ZonedDateTime date
	    -Recipe usedRecipe
	    -int quantityCrafted
        -int craftingTimeInMilliseconds

	    +ZonedDateTime getDate()
	    +Recipe getUsedRecipe()
	    +int getQuantityCrafted()
        +int getCraftingTimeInMilliseconds()
    }

    class Inventory {
        -HashMap~Item, Integer~ items

	    +HashMap~Item, Integer~ getItems()
	    +Item getItemQuantity(Item item)
	    +void addItem(Item item, int quantity)
	    +void removeItem(Item item, int quantity)
        +void storeOnJSON(String path)
        +static Inventory loadFromJSON(String path)
        +String toString(String itemMarker, int lPadding)
    }

    class Ingredient {
	    -Item item
	    -int quantity

	    +Item getItem()
	    +int getQuantity()
        +String toString(String itemMarker, int lPadding)
    }

    class CraftingSystem {
	    -Item itemToCraft
        -int quantityToCraft
	    -Inventory inventory
	    -CraftingHistory history

        +List~CraftedItem~ getCraftedItems()
	    +int getCraftableUnits()
        -int getCraftableUnits(Recipe recipe)
        +HashMap~Recipe, List~Ingredient~~ getMissingIngredients()
        +HashMap~Recipe, List~Ingredient~~ getMissingBaseIngredients(int branch)
        -HashMap~Recipe, List~Ingredient~~ getMissingIngredients(HashMap~Recipe, List~Ingredient~~ recipes)
	    +HashMap~Recipe, List~Ingredient~~ getRequiredIngredients()
        +HashMap~Recipe, List~Ingredient~~ getRequiredBaseIngredients(int branch)
        -List~Ingredient~ getBaseIngredientsRecursive(Recipe recipe, int totalToCraft, int branch, Set~Item~ processedCraftingTables)
	    +boolean canCraft()
	    +void setItemToCraft(Item item, int quantity)
	    +CraftedItem craftItem(int recipe)
	    +CraftedItem undoLastCraft()
    }

    class CraftingHistory {
	    -List~CraftedItem~ items

        +List~CraftedItem~ getItems()
        +CraftedItem getLastItem()
	    +void addItem(Item item, Recipe usedRecipe)
	    +CraftedItem removeLastItem()
    }

    ItemsRepository "1" --o "0...*" Item : Has

    PrologService "1" --o "1" Inventory : Has a reference to
    PrologService "1" --o "1" ItemsRepository : Has a reference to

    Item "1" --o "0...*" Recipe : Has

    Recipe "1" --o "1...*" Ingredient : Has
    Recipe "1" --o "0...1" Item : Has a reference to

    CraftedItem --|>  Item : Inherits from

    Inventory "1" --o "0...*" Item : Has references to

    CraftingSystem "1*" --o "0..." Item : Has references to
    CraftingSystem "1" --o "1" Inventory : Has a reference to
    CraftingSystem "1" --* "1" CraftingHistory : Has

    CraftingHistory "1" --o "0...*" CraftedItem : Has
Loading

Note

The diagrams were developed from scratch as part of the preliminary project reports.

Team workflow

---
config:
  logLevel: debug
  theme: base
  gitGraph:
    showBranches: true
    showCommitLabel: true
    mainBranchName: Master
    parallelCommits: true
---
gitGraph:
        commit
        commit tag: "v0.0.1"
        branch "Aguilera Emanuel"
        commit
        commit
        checkout Master
        branch "De Marco Juan"
        commit
        commit
        checkout Master
        branch "Hoz Lucas"
        commit
        commit
        checkout Master
        branch "Rueda Olarte Joel"
        commit
        commit
        checkout Master
        branch "Maudet Alejandro"
        commit
        commit
        checkout Master
        branch "Monges Omar"
        commit
        commit
        checkout Master
        merge "De Marco Juan"
        merge "Aguilera Emanuel"
        merge "Rueda Olarte Joel"
        merge "Maudet Alejandro"
        merge "Hoz Lucas"
        merge "Monges Omar" tag: "v1.0.0"
Loading

Tags

  • vMAJOR.MINOR.PATCH: This tag indicates a release of the practical work following Semantic Versioning, and will only be present in the Master branch commits.

Branches

  • Master: Branch containing the development versions of the practical work, where team members will introduce new changes (commits).

Important

Stable versions are only available as releases.

Note

The other branches are fictional and represent individual contributions from each member to the Master branch.

Development team

Additional material

License

This repository is under the MIT License. For more information about what is permitted with the contents of this repository, visit choosealicense.com.

Acknowledgments

We would like to thank the teachers from the UNLaM Programming Paradigms course for their support and guidance.