Skip to content

Project 1#1

Open
dernov333-ai wants to merge 3 commits intomainfrom
dev
Open

Project 1#1
dernov333-ai wants to merge 3 commits intomainfrom
dev

Conversation

@dernov333-ai
Copy link
Owner

Привет, моя первая работа

Comment on lines +8 to +9
final int RaceleMan = 24;
final int CarCount = 3;

Choose a reason for hiding this comment

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

Эти две переменные можно положить в константы на уровне класса, чтобы не объявлять их внутри метода, там же их можно назвать в соответствии с SCREAMING_SNAKE_CASE как настоящие константы)

final int RaceleMan = 24;
final int CarCount = 3;

Auto[] cars = new Auto[CarCount];

Choose a reason for hiding this comment

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

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

String input = scanner.nextLine().trim();
try {
speed = Integer.parseInt(input);
if (speed > 0 && speed <= 250) {

Choose a reason for hiding this comment

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

Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода

Comment on lines +46 to +47
private final String name;
private final int speed;

Choose a reason for hiding this comment

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

Так как переменные помечены модификатором final, то можно сделать их публичными и убрать геттеры, получая доступ к данным напрямую по имени поля - будет так же надёжно и безопасно

return speed;
}

public int distanceЗа24Часа() {

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