Conversation
…on, statistics output and the README was edited
| @@ -1 +1,23 @@ | |||
| # Island | |||
| ## Description | |||
| int ans; | ||
| try { | ||
| ans = scanner.nextInt(); | ||
| if (ans < 0 || ans > 5) { | ||
| System.out.println(Constant.INVALID_NUMBER_PLEASE_TRY_AGAIN); | ||
| continue; | ||
| } | ||
| } catch (InputMismatchException e) { | ||
| String badValue = scanner.nextLine(); | ||
| System.out.println(Constant.IT_S_NOT_A_NUMBER + badValue); | ||
| continue; | ||
| } | ||
|
|
||
| if (ans != 5) { | ||
| System.out.print(Constant.WRITE_THE_PARAMETER_VALUE); | ||
| } | ||
| if (ans == 1) { | ||
| paramType = Constant.MAP_WIDTH; | ||
| } | ||
| if (ans == 2) { | ||
| paramType = Constant.MAP_HEIGHT; | ||
| } | ||
| if (ans == 3) { | ||
| paramType = Constant.COUNT_ENTITIES_IN_ONE_LOCATION; | ||
| } | ||
| if (ans == 4) { | ||
| paramType = Constant.LIFE_CYCLE_OF_SIMULATION; | ||
| } | ||
| if (ans == 5) { | ||
| break; | ||
| } |
There was a problem hiding this comment.
это можно вынести в отдельный сервис ввода данных, чтобы было более читаемо и был нормальный код. Плюс можно вынести в enum и сделать вот так
enum SomeEnum {
VALUE(1, Constant.WRITE_THE_PARAMETER_VALUE),
VALUE2(2, Constant.MAP_WIDTH) и так далее и сделать switch case на этот enum
| } | ||
|
|
||
| @Override | ||
| public void doEat(Animal animal, Location location) { |
There was a problem hiding this comment.
раздели на несколько маленьких методов, так его будет проще прочитать
| int currentX = location.getX(); | ||
| int currentY = location.getY(); | ||
| if (currentX < map.getWidth() - 1) { | ||
| Location newLocation = map.getLocations()[currentY][currentX + 1]; | ||
| if (cantStep(animal, newLocation)) { | ||
| return location; | ||
| } | ||
| newLocation.addEntity(animal); | ||
| location.removeEntity(animal); | ||
| return newLocation; | ||
| } | ||
| return location; |
There was a problem hiding this comment.
все методы шаблонные - подумай как можно сократить кол-во кода
| import java.io.IOException; | ||
| import java.util.Properties; | ||
|
|
||
| public class Processor { |
There was a problem hiding this comment.
весь этот класс можно было вынести на два-три метода, String getValue(String param, String key)
и Doube getValue(String param, String key) и int getValue(String param, String key)
где key был бы ".emoji" или ".weight" и так далее
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| public class Statistic { | ||
| public static final String EMOJI_KEY_VALUE = "{0} - {1}"; |
There was a problem hiding this comment.
Тут точно нужна public переменная?
No description provided.