Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Тачки #1

Open
Alinochka-21 wants to merge 4 commits intomain from
dev
Open

Тачки #1
Alinochka-21 wants to merge 4 commits intomain from
dev

Conversation

@Alinochka-21
Copy link
Owner

@Alinochka-21 Alinochka-21 commented Nov 18, 2025

Создала консольное приложение

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.

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

Comment on lines 2 to 3
String name;
int speed;
Copy link

@ArturNurtdinov ArturNurtdinov Nov 18, 2025

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

@Alinochka-21 Alinochka-21 Nov 23, 2025

Choose a reason for hiding this comment

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

смогла пометить name как final, но speed инициализируется в мейне, иначе бы пришлось метод в этом классе объявлять для инициализации

Comment on lines 4 to 6
Car(){
this(null,0);
}
Copy link

@ArturNurtdinov ArturNurtdinov Nov 18, 2025

Choose a reason for hiding this comment

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

Пустой конструктор можно удалить, т.к. смысла в объекте, у которого name = null, а speed = 0, - мало

Copy link
Owner Author

@Alinochka-21 Alinochka-21 Nov 23, 2025

Choose a reason for hiding this comment

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

удалила пустой конструктор

System.out.println("Hello world!");
Scanner input = new Scanner(System.in);

ArrayList<Car> cars = new ArrayList<>();
Copy link

@ArturNurtdinov ArturNurtdinov Nov 18, 2025

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

@Alinochka-21 Alinochka-21 Nov 23, 2025

Choose a reason for hiding this comment

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

я ввела константы, общую переменную для победителя и для сохранения максимальной дистанции.

Copy link
Owner Author

@Alinochka-21 Alinochka-21 Nov 23, 2025

Choose a reason for hiding this comment

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

убрала коллекции и по мере появления нового авто меняла победителя

System.out.println("Введите скорость машины - просто напишите целое число от 1 до 250 включительно:");
if (input.hasNextInt()) {
car.speed = input.nextInt();
if (car.speed > 0 && car.speed <= 250) {
Copy link

@ArturNurtdinov ArturNurtdinov Nov 18, 2025

Choose a reason for hiding this comment

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

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

Copy link
Owner Author

Alinochka-21 commented Nov 18, 2025 via email

Поняла, спасибо! Вт, 18 нояб. 2025 г. в 06:32, Artur ***@***.***>:
...
***@***.**** commented on this pull request. Хорошая работа, молодец! ------------------------------ In src/main/java/Car.java <#1 (comment)> : > + String name; + int speed; Поля лучше пометить final, тем самым исключив возможность их модификации извне ------------------------------ In src/main/java/Car.java <#1 (comment)> : > + Car(){ + this(null,0); + } Пустой конструктор можно удалить, т.к. смысла в объекте, у которого name = null, а speed = 0, - мало ------------------------------ In src/main/java/Main.java <#1 (comment)> : > public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + Scanner input = new Scanner(System.in); + + ArrayList<Car> cars = new ArrayList<>(); От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее ------------------------------ In src/main/java/Main.java <#1 (comment)> : > + + ArrayList<Car> cars = new ArrayList<>(); + cars.add(new Car()); + cars.add(new Car()); + cars.add(new Car()); + + System.out.println("Привет! Сейчас тебе надо ввести данные о трех машинах, просто следуй инструкциям :)"); + + for (Car car : cars) { + System.out.println("Введите имя машины:"); + car.name = input.next(); + while (true) { + System.out.println("Введите скорость машины - просто напишите целое число от 1 до 250 включительно:"); + if (input.hasNextInt()) { + car.speed = input.nextInt(); + if (car.speed > 0 && car.speed <= 250) { Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода — Reply to this email directly, view it on GitHub <#1 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BQLWMGOMLGFTFQVR7JYUCV335KHNFAVCNFSM6AAAAACMM457VOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTINZVGMZDSNBVGQ> . You are receiving this because you authored the thread.Message ID: ***@***.***>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@ArturNurtdinov ArturNurtdinov ArturNurtdinov left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /