Skip to content

1 попытка сдачи проекта - #2

Open
MiDoRe1 wants to merge 8 commits into
mainfrom
dev
Open

MiDoRe1 wants to merge 8 commits into
mainfrom
dev

Conversation

@MiDoRe1

@MiDoRe1 MiDoRe1 commented Dec 13, 2025

Copy link
Copy Markdown
Owner

В проекте 4 основных класса:
Main - точка входа в программу и организацию взаимодействия между классами;
InteracterWithUserViaConsole - класс отвечает за взаимодействие с пользователем и валидацию данных;
Race - класс для выбора победителя;
Car - данные по участникам гонки;

Comment thread src/main/java/Car.java
Comment on lines +2 to +4
String name;
int speed;
int serialNumber;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Поля лучше пометить final, тем самым исключив возможность их модификации извне


public class InteracterWithUserViaConsole {
public ArrayList<Car> getCarsForRace( int totalOfCars, int minSpeed, int maxSpeed) {
ArrayList<Car> carsForRace = new ArrayList<>(totalOfCars);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +19 to +23
while ( !isValidNameInformation(nameOfCar) ) {
System.out.println("Невалидный ввод.");
System.out.println(String.format("Введите название машины №%d:", serialNumber));
nameOfCar = scanner.nextLine();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать

Comment thread src/main/java/Main.java
Comment on lines +5 to +8
public static int totalOFCars = 3;
public static int hoursInRace = 24;
public static int minSpeedOfVehicle = 0;
public static int maxSpeedOfVehicle = 250;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Молодец, что вынес эти значения в параметры, но лучше их сделать настоящими константами, для этого нужно добавить модификатор final и переименовать в соответствии со SCREAMING_SNAKE_CASE, например так:
public static final int TOTAL_OF_CARS = 3;

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