Skip to content

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

Open
shrunzy wants to merge 2 commits intomainfrom
dev
Open

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

Conversation

@shrunzy
Copy link
Owner

@shrunzy shrunzy commented Dec 24, 2025

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


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;

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<>();

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) {

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; // высчитываем расстояние, которое пройдет автомобиль

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants