https://github.com/karynaaliushkevich14/task
Based on the existing code, write an implementation of the method findBlockByColor(), findBlocksByMaterial(), count()
https://github.com/karynaaliushkevich14/task
java oop
Last synced: about 1 year ago
JSON representation
Based on the existing code, write an implementation of the method findBlockByColor(), findBlocksByMaterial(), count()
- Host: GitHub
- URL: https://github.com/karynaaliushkevich14/task
- Owner: KarynaAliushkevich14
- Created: 2023-02-25T21:04:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-27T08:35:59.000Z (over 3 years ago)
- Last Synced: 2025-04-09T03:39:21.586Z (about 1 year ago)
- Topics: java, oop
- Language: Java
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Zadanie:
Na podstawie istniejącego kodu napisać implementację metod findBlockByColor(), findBlocksByMaterial(), count()
# Rozwiązanie:
W istniejącym programie możemy zauważyć, że interface CompositeBlock rozszerza interface Block, natomiast metoda List getBlocks() znajduje się w interfejsie CompositeBlock.
Oznacza to, że zmienna List blocks w klasie Wall może przechowywać nie tylko zwykłe bloki, ale także bloki kompozytowe składające się z innych bloków.
Wszystkie trzy metody sprawdzają typ bloku i w zależności od tego rozwiązują problem.
# Task:
Based on the existing code, write an implementation of the method findBlockByColor(), findBlocksByMaterial(), count()
# Solution:
In the existing program, we can notice that interface CompositeBlock extends interface Block, while the List getBlocks() method is located in the CompositeBlock interface.
This means that the List blocks variable in the Wall class can store not only ordinary blocks, but also composite blocks consisting of other blocks.
All three methods check the block type and solve the problem based on this.