Skip to content

Initial commit#1

Open
cherrevkoo wants to merge 1 commit intomainfrom
dev
Open

Initial commit#1
cherrevkoo wants to merge 1 commit intomainfrom
dev

Conversation

@cherrevkoo
Copy link
Owner

No description provided.

Comment on lines +2 to +3
String name;
int speed;

Choose a reason for hiding this comment

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

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


while (true) {
System.out.println("Введите имя гонщика: ");
inputName = scanner.nextLine();

Choose a reason for hiding this comment

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

Лучше тут ещё воспользоваться функцией trim(), чтобы не позволять вводить название машин, состоящие только из пробелов и переносов строк

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

Choose a reason for hiding this comment

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

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

inputSpeed = scanner.nextInt();
scanner.nextLine();

if (inputSpeed > 0 && inputSpeed < 250) {

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