-
Notifications
You must be signed in to change notification settings - Fork 0
commit #1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
commit #1 #1
Conversation
ArturNurtdinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хорошая работа, молодец!
| @@ -0,0 +1,15 @@ | |||
| public class Car { | |||
| final static int HOURS = 24; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Константу лучше вынести в класс Race, так как эта константа означает продолжительность гонки
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| ArrayList<Car> cars = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее
| final static int MIN_SPEED = 1; | ||
| final static int MAX_SPEED = 250; | ||
| final static int NUM_CARS = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Всю логику из класса Main лучше вынести в отдельный класс и файл, чтобы в Main остался только запуск программы
| while (!trueName) { | ||
| System.out.print("Наименование: "); | ||
| name = scanner.nextLine().trim(); | ||
| if (name.isEmpty()) | ||
| System.out.println("Ошибка. Пустое название недопустимо"); | ||
| else | ||
| trueName = true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать
| while (!trueSpeed) { | ||
| System.out.print("Скорость в км/ч, от " + MIN_SPEED + " до " + MAX_SPEED + ": "); | ||
| if (scanner.hasNextInt()) { | ||
| speed = scanner.nextInt(); | ||
| if ((speed >= MIN_SPEED) && (speed <= MAX_SPEED)) | ||
| trueSpeed = true; | ||
| else | ||
| System.out.println("Ошибка. Введите допустимую скорость"); | ||
| } else | ||
| System.out.println("Ошибка. Введите целое число"); | ||
| scanner.nextLine(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Код для считывания скорости тоже лучше вынести в отдельную функцию
Спринт Yandex-Practicum#2. Pull Request #1.