Skip to content

Conversation

@alekstalla
Copy link
Owner

Спринт Yandex-Practicum#2. Pull Request #1.

Copy link

@ArturNurtdinov ArturNurtdinov left a comment

Choose a reason for hiding this comment

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

Хорошая работа, молодец!

@@ -0,0 +1,15 @@
public class Car {
final static int HOURS = 24;

Choose a reason for hiding this comment

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

Константу лучше вынести в класс Race, так как эта константа означает продолжительность гонки

public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
ArrayList<Car> cars = new ArrayList<>();

Choose a reason for hiding this comment

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

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

Comment on lines +5 to +7
final static int MIN_SPEED = 1;
final static int MAX_SPEED = 250;
final static int NUM_CARS = 3;

Choose a reason for hiding this comment

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

Всю логику из класса Main лучше вынести в отдельный класс и файл, чтобы в Main остался только запуск программы

Comment on lines +16 to +23
while (!trueName) {
System.out.print("Наименование: ");
name = scanner.nextLine().trim();
if (name.isEmpty())
System.out.println("Ошибка. Пустое название недопустимо");
else
trueName = true;
}

Choose a reason for hiding this comment

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

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

Comment on lines +28 to +39
while (!trueSpeed) {
System.out.print("Скорость в км/ч, от " + MIN_SPEED + " до " + MAX_SPEED + ": ");
if (scanner.hasNextInt()) {
speed = scanner.nextInt();
if ((speed >= MIN_SPEED) && (speed <= MAX_SPEED))
trueSpeed = true;
else
System.out.println("Ошибка. Введите допустимую скорость");
} else
System.out.println("Ошибка. Введите целое число");
scanner.nextLine();
}

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.

3 participants