Conversation
| new Car(2020, "e555ee55", "red", "skoda") | ||
| }; | ||
|
|
||
| CarService dataBase = new CarService(cars); |
There was a problem hiding this comment.
database - это одно слово:) но название некорректно - carService и очевиднее и лучше. Так-то, он не обязан хранить данные - вполне может обращаться внутри себя к другому классу, ответственному за хранение
| hashcode += color == null ? 0 : color.hashCode(); | ||
| hashcode += model == null ? 0 : model.hashCode(); | ||
| } | ||
| return hashcode; |
There was a problem hiding this comment.
нарушен контракт equals-hashcode. Сейчас у одинаковых по икуалз объектов могут быть разные хэшкоды, что недопустимо
| hashcode += color == null ? 0 : color.hashCode(); | ||
| hashcode += model == null ? 0 : model.hashCode(); | ||
| } | ||
| return hashcode; |
There was a problem hiding this comment.
не хватает пустой строки перед return. И поехала табуляция. ctrl+alt+L - автоформатирование кода
| @@ -0,0 +1,18 @@ | |||
| package com.walking.lesson19_object_methods.model; | |||
|
|
|||
| public class CarService { | |||
There was a problem hiding this comment.
сервис - не модель. Обычно сервисы выносят в отдельный пакет
| public class CarService { | ||
| private final Car[] cars; | ||
|
|
||
| public CarService(Car[] allcars) { |
There was a problem hiding this comment.
переменные, прааметры методов и поля именуются в camelCase. Т.е. здесь - allCars. Впрочем, просто cars было бы достаточно
| this.cars = allcars; | ||
| } | ||
|
|
||
| public Car searchCar(Car userCar) { |
There was a problem hiding this comment.
нет смысла в постфиксе Car. Вполне логично, что метод поиска в CarService ищет объекты типа Car. Т.е. можно назвать метод search. Или, что более распространено - find
| } | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
опционально можно добавить методы добавления, изменения и удаления машины. Это не обязательно по условию, но выглядит логично в контексте работы с подобным приложением
|
|
||
| public class File { | ||
| private String fileName; | ||
| private final FileType fileType; |
There was a problem hiding this comment.
почему я могу менять все, кроме типа файла? Вполне логично заменить, например, txt на sql/properties/другой текстовый формат. В целом, мелкое замечание
| private final FileType fileType; | ||
| private int fileSize; | ||
|
|
||
| public File(String fileName, FileType fileType, int fileSize){ |
| } | ||
|
|
||
| @Override | ||
| public String toString(){ |
|
|
||
| public File search (String userFile) throws FileNotFoundException { | ||
| for (File file : files) { | ||
| if (userFile.equals(file.getFileName())) { |
There was a problem hiding this comment.
в File не переопределен икуалз
| @@ -0,0 +1,7 @@ | |||
| package com.walking.lesson20_exceptions.task1_throwsException.service; | |||
|
|
|||
| public class FileNotFoundException extends Exception{ | |||
There was a problem hiding this comment.
не хватает пробела перед {. Логичнее было бы наследоваться от RuntimeException - ты ведь файл ищешь не в файловой системе, а в ин-меморе хранилке - массиве
| if (userFigure == 1) { | ||
| figure = new Square(); | ||
| } else { | ||
| figure = new Triangle(); |
There was a problem hiding this comment.
хватило бы тернарки. Или switch-case, который выглядел бы лучше при потениальном увеличении числа наследников фигуры
| } else { | ||
| figure = new Triangle(); | ||
| } | ||
| System.out.println(figure.buildFigure(userWidth)); |
There was a problem hiding this comment.
пустая строка перед этой строчкой
| @@ -0,0 +1,22 @@ | |||
| package com.walking.lesson20_exceptions.task2.model; | |||
|
|
|||
| public class Square implements Figure{ | |||
| @@ -0,0 +1,7 @@ | |||
| package com.walking.lesson20_exceptions.task2.service; | |||
|
|
|||
| public class InputValidationException extends RuntimeException{ | |||
| public class Main { | ||
| public static void main(String[] args) { | ||
| Animal[] animals = {new Cat(), new Dog(), new Cow()}; | ||
| soundAll(animals); |
Lesson 19 is done.
Lesson 20 all tasks done.