OOP - FIIT STU

Cvičenie 2

Trieda, inštancia, balík, metóda, princípy OOP

Cvičenie 2 - OOP pojmy

Pred cvičením

  • Overte, že máte založený repozitár k semestrálnemu projektu - cvičiaci vám minulý týždeň poslal pozvánku.
  • Overte, že viete spraviť lokálny commit a push do repozitára.
    Interaktívny kurz GitHub nájdete na stránke s materiálmi - Git by Bit

Úlohy

  1. Konzultujte Špecifikáciu (1. zadanie) so svojím cvičiacim, dohodnite sa na téme a rozsahu zadania. Mali by ste s ním prejsť tému, hlavnú myšlienku a približný rozsah projektu.

Java úlohy

Ak vám v IDE nepôjde načítať default-structure v rámci projektu, konzultujte tento návod. Tiež si môžete nainštalovať plugin do IDE - ten za vás zabezpečí stiahnutie, načítanie a tiež odovzdanie úlohy. Pokyny sú na konci návodu.

Download the skeleton files

Inheritance, Encapsulation, Polymorphism & Method Overloading

Nakoľko sú všetky premenné a časti kódu v Angličtine, tak aj dnešné zadanie úlohy je v angličtine. Cieľom je aby ste si vyskúšali základné OOP koncepty v Jave.

In this task you will build a simple RPG character system — no UI needed, just the core class hierarchy and game logic. You will practise the most important OOP pillars:

ConceptWhat you practise
InheritanceBuilding a class hierarchy (Warrior, Mage, Archer extend GameCharacter)
EncapsulationPrivate fields, getters / setters, no leaking of internal state
Method overridingEach subclass overrides getCharacterType(), calculateDamage(), getInfo()
Method overloadingattack() / attack(GameCharacter) in GameCharacter; castSpell() overloads in Mage
Runtime polymorphismUsing GameCharacter references to call overridden methods
Access modifiersprivate vs protected fields inside an inheritance hierarchy

Provided skeleton files

Two skeleton files live in org.jikvict.tasks.exposed:

FileDescription
GameCharacter.javaAbstract base class — read the TODOs inside
Weapon.javaSimple weapon class — read the TODOs inside

Do not change method signatures or access modifiers that are already present. You may add private helper methods if you need them.


What you must implement

Quick example

GameCharacter warrior = new Warrior("Arthur", 100, 10, 6);
GameCharacter mage    = new Mage("Gandalf", 80, 15, 50);

System.out.println(warrior.getCharacterType()); // "Warrior"
System.out.println(mage.calculateDamage());     // 30

warrior.attack(mage);            // mage takes damage
System.out.println(warrior.attack()); // prints damage value (no target attacked)

Submission

Na odovzdanie úlohy môžete použiť aj plugin v InteliJ IDEA Jikvict, ktorý vám automaticky stiahne, nahrá a odovzdá úlohu. Postup nájdete na stránke pomoci.

Take your whole project, remove unnecessary files (like .idea folder or build folder) and zip it.

The final zip file should contain the default-structure folder at the root.

On this page