Skip to content

Conversation

@iandrianov
Copy link
Owner

Car and race classes, race formation methods, and winner determination methods have been added. The winner's name is also now displayed in the console.

…n methods have been added. The winner's name is also now displayed in the console.
Comment on lines +2 to +3
int speed;
String name;

Choose a reason for hiding this comment

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

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

Comment on lines +46 to +57
String[] frames = {
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨",
" 🚗💨"
};

Choose a reason for hiding this comment

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

Массив можно вынести в константу, чтобы не создавать на каждый вызов функции новый массив


for (String frame : frames) {
System.out.print("\r" + frame);
Thread.sleep(150);

Choose a reason for hiding this comment

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

Значение задержки лучше вынести в константу для повышения читабельности кода

import java.util.Scanner;

public class Race {
ArrayList<Car> raceParticipants = new ArrayList<>();

Choose a reason for hiding this comment

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

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

if (scanner.hasNextInt()) {
speed = scanner.nextInt();
scanner.nextLine();
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.

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

return winner;
}

static void Print(String text) {

Choose a reason for hiding this comment

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

В джава функции принято именовать с маленькой буквы


if (car.name.equalsIgnoreCase("Lada") || car.name.equalsIgnoreCase("Лада") || car.name.equalsIgnoreCase("Жигули")) {
System.out.println("🚗 " + car.name + " получает бонус! +100 к скорости 💨");
car.speed += 100;

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