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

Консольное приложение, спринт 2#1

Open
shrunzy wants to merge 2 commits intomain from
dev
Open

Консольное приложение, спринт 2 #1
shrunzy wants to merge 2 commits intomain from
dev

Conversation

@shrunzy
Copy link
Owner

@shrunzy shrunzy commented Dec 24, 2025
edited by cursor bot
Loading

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


Note

Implements a minimal console program to collect car data, validate input, and determine the fastest car.

  • New Car model to store carName and carSpeed
  • New Winner class with calculateWinner to pick the car with max distance over 24 hours (speed * 24)
  • Main replaced to prompt for 3 cars, validate integer speeds within (0, 250], build a list, compute, and print the winner (winner.winnerStr)

Written by Cursor Bugbot for commit c1e8623. This will update automatically on new commits. Configure here.

Comment on lines +2 to +3
String carName;
int carSpeed;
Copy link

@ArturNurtdinov ArturNurtdinov Dec 24, 2025

Choose a reason for hiding this comment

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

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


Scanner scanner = new Scanner(System.in);
Winner winner = new Winner();
ArrayList<Car> carStorage = new ArrayList<>();
Copy link

@ArturNurtdinov ArturNurtdinov Dec 24, 2025

Choose a reason for hiding this comment

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

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

String carName = scanner.next();
scanner.nextLine();

while (true) {
Copy link

@ArturNurtdinov ArturNurtdinov Dec 24, 2025

Choose a reason for hiding this comment

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

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


for (int i = 1; i <= carStorage.size(); i++) {
Car carElement = carStorage.get(i-1); // получаем объект автомобиль
newDistance = carElement.carSpeed*24; // высчитываем расстояние, которое пройдет автомобиль
Copy link

@ArturNurtdinov ArturNurtdinov Dec 24, 2025

Choose a reason for hiding this comment

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

Число 24 лучше вынести в константу с говорящим названием для повышения читабельности кода

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 によって変換されたページ (->オリジナル) /