Skip to content

Conversation

@johnmango
Copy link

@johnmango johnmango commented May 17, 2024

Lesson 19 is done.
Lesson 20 all tasks done.

@johnmango johnmango changed the title Lesson 19 PR Lesson 19 and 20 May 21, 2024
new Car(2020, "e555ee55", "red", "skoda")
};

CarService dataBase = new CarService(cars);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

database - это одно слово:) но название некорректно - carService и очевиднее и лучше. Так-то, он не обязан хранить данные - вполне может обращаться внутри себя к другому классу, ответственному за хранение

hashcode += color == null ? 0 : color.hashCode();
hashcode += model == null ? 0 : model.hashCode();
}
return hashcode;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нарушен контракт equals-hashcode. Сейчас у одинаковых по икуалз объектов могут быть разные хэшкоды, что недопустимо

hashcode += color == null ? 0 : color.hashCode();
hashcode += model == null ? 0 : model.hashCode();
}
return hashcode;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хватает пустой строки перед return. И поехала табуляция. ctrl+alt+L - автоформатирование кода

@@ -0,0 +1,18 @@
package com.walking.lesson19_object_methods.model;

public class CarService {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сервис - не модель. Обычно сервисы выносят в отдельный пакет

public class CarService {
private final Car[] cars;

public CarService(Car[] allcars) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переменные, прааметры методов и поля именуются в camelCase. Т.е. здесь - allCars. Впрочем, просто cars было бы достаточно

this.cars = allcars;
}

public Car searchCar(Car userCar) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет смысла в постфиксе Car. Вполне логично, что метод поиска в CarService ищет объекты типа Car. Т.е. можно назвать метод search. Или, что более распространено - find

}
}
return null;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

опционально можно добавить методы добавления, изменения и удаления машины. Это не обязательно по условию, но выглядит логично в контексте работы с подобным приложением


public class File {
private String fileName;
private final FileType fileType;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему я могу менять все, кроме типа файла? Вполне логично заменить, например, txt на sql/properties/другой текстовый формат. В целом, мелкое замечание

private final FileType fileType;
private int fileSize;

public File(String fileName, FileType fileType, int fileSize){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробел перед {

}

@Override
public String toString(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.


public File search (String userFile) throws FileNotFoundException {
for (File file : files) {
if (userFile.equals(file.getFileName())) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в File не переопределен икуалз

@@ -0,0 +1,7 @@
package com.walking.lesson20_exceptions.task1_throwsException.service;

public class FileNotFoundException extends Exception{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хватает пробела перед {. Логичнее было бы наследоваться от RuntimeException - ты ведь файл ищешь не в файловой системе, а в ин-меморе хранилке - массиве

if (userFigure == 1) {
figure = new Square();
} else {
figure = new Triangle();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хватило бы тернарки. Или switch-case, который выглядел бы лучше при потениальном увеличении числа наследников фигуры

} else {
figure = new Triangle();
}
System.out.println(figure.buildFigure(userWidth));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пустая строка перед этой строчкой

@@ -0,0 +1,22 @@
package com.walking.lesson20_exceptions.task2.model;

public class Square implements Figure{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробел

@@ -0,0 +1,7 @@
package com.walking.lesson20_exceptions.task2.service;

public class InputValidationException extends RuntimeException{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробел

public class Main {
public static void main(String[] args) {
Animal[] animals = {new Cat(), new Dog(), new Cow()};
soundAll(animals);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лишний таб.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants