Cvičenie 5
Interfaces & Java Initialization Order: The Plant Shop
Cvičenie 5 - GUI & Plánovanie
Úlohy
- Pokračujte v práci na svojom semestrálnom projekte. Nezabudnite pracovať pravidelne, a to tempom minimálne 2 commity týždenne. Každý commit by mal predstavovať zmysluplnú funkciu alebo vylepšenie.
- Neváhajte požiadať o pomoc a prekonzultovať svoje nápady s učiteľom.
- Odporúča sa začať s tromi časťami projektu: doménovým modelom – logikou, testovacím prostredím a užívateľským rozhraním.
Ďalšie odovzdanie je Zadanie 2 - checkpoint. Dátum 29.03.2026.
Java Úlohy
Task 9 — Interfaces & Java Initialization Order: The Plant Shop
Understanding Interfaces, Inheritance, and How Java Brings Your Code to Life
In this task you will build a plant shop system where different plants (flowers, succulents, herbs) each have unique growing and treatment behaviours defined through interfaces you design yourself. Along the way you will explore how Java actually initializes classes and objects — the exact order in which static blocks, instance blocks, field initializers, and constructors execute, including across an inheritance hierarchy.
This task has two parts:
| Part | What you will learn |
|---|---|
| Part 1 — Interfaces & the Plant Shop | Design and implement your own interfaces; have classes implement multiple interfaces; understand interface contracts |
| Part 2 — Initialization Order Playground | Discover — by running code and observing output — the precise order Java uses to load classes, initialize fields, execute initializer blocks, and call constructors |
Provided files
All files live in package org.jikvict.tasks.exposed:
| File | Status | Description |
|---|---|---|
Plant.java | Provided | Abstract base class for all plants — contains static/instance initializer blocks and prints initialization messages |
PlantShop.java | Provided | A simple shop that holds plants — students add plants and interact with them |
InitializationPlayground.java | Provided | A playground class for experimenting with initialization order — run it, read the output, answer the questions |
Main.java | Provided | Entry point — uncomment sections as you implement |
Do not change method signatures or access modifiers in provided files. You may add private helper methods if you need them.
Summary
| What to create | Type |
|---|---|
Growable.java | Interface (you write it) |
Treatable.java | Interface (you write it) |
Sellable.java | Interface (you write it) |
Flower.java | Class extending Plant, implementing Growable, Treatable |
Succulent.java | Class extending Plant, implementing Growable |
Herb.java | Class extending Plant, implementing Growable, Treatable, Sellable |