Created
October 31, 2021 18:11
-
-
Save amirkenesbay/90e27aaeab32b5cfe0d99297250eb53f to your computer and use it in GitHub Desktop.
Как сделать код в стиле MVC?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
У меня есть учебное задание. Возникает вопрос как все это сделать в архитектурном стиле MVC? Ниже я еще указал не реализованные классы и интерфейс. Не могу понять что и как определенные классы реализовывать, что и откуда вызывать и так далее. Описание такое: | |
Рыцарь. Определить иерархию амуниции рыцаря. Операции с рыцарем: | |
Вывести характеристики рыцаря | |
Вывести список амуниции рыцаря | |
Экипировать рыцаря, что должно отразиться на его характеристиках (например вес, сила атаки и т.д.) | |
Провести сортировку амуниции на основе одного из параметров | |
Найти элементы амуниции, соответствующие заданному диапазону параметров. | |
Пример ввода/вывода | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
2 | |
Sword{damage=10, weight=20, cost=30} | |
Helmet{protection=30, weight=10, cost=20} | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
3 | |
What kind of ammunition do you want to equip? | |
1. Sword | |
2. Helmet | |
Choose option: | |
1 | |
Input sword weight: | |
100 | |
Input sword cost: | |
2 | |
Input sword damage: | |
30 | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
2 | |
Sword{damage=10, weight=20, cost=30} | |
Helmet{protection=30, weight=10, cost=20} | |
Sword{damage=30, weight=100, cost=2} | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
1 | |
Ammunition cost: 52 | |
Ammunition weight: 130 | |
Ammunition damage: 40 | |
Ammunition protection: 30 | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
4 | |
Choose sort type: | |
1. Cost | |
2. Weight | |
Choose option: | |
2 | |
Helmet{protection=30, weight=10, cost=20} | |
Sword{damage=10, weight=20, cost=30} | |
Sword{damage=30, weight=100, cost=2} | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
5 | |
Choose search field: | |
1. Cost | |
2. Weight | |
Choose option: | |
1 | |
Input minimum cost: | |
0 | |
Input maximum cost: | |
5 | |
Sword{damage=30, weight=100, cost=2} | |
Main menu: | |
1. Print knight stats | |
2. Show ammunition | |
3. Equip ammunition | |
4. Sort ammunition | |
5. Search ammunition | |
6. Exit | |
Choose option: | |
6 | |
Bye! | |
public class KnightApplication { | |
public static void main(String[] args) { | |
KnightApplication application = new KnightApplication(); | |
application.start(); | |
} | |
private void start() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
} | |
public class Knight { | |
private Ammunition[] ammunition; | |
public Ammunition[] getAmmunition() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
/** | |
* Add new ammunition element to knight | |
* @param element that should be equipped to the knight | |
*/ | |
public void equip(Ammunition element) { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
public int calculateAmmunitionWeight() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
public int calculateAmmunitionCost() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
public int calculateAmmunitionDamage() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
public int calculateAmmunitionProtection() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
} | |
public class KnightGenerator { | |
/** | |
* Use it to quickly generate knight | |
* @return knight | |
*/ | |
public static Knight generateKnight() { | |
throw new UnsupportedOperationException("You need to implement this method"); | |
} | |
} | |
public interface Ammunition { | |
int getWeight(); | |
int getCost(); | |
} | |
public class ConsoleView { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment