-
Notifications
You must be signed in to change notification settings - Fork 0
Приложение функционирует #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?
Conversation
src/main/java/Auto.java
Outdated
String name; | ||
int speed; |
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
, тем самым исключив возможность их модификации извне
src/main/java/Auto.java
Outdated
public class Auto { | ||
String name; | ||
int speed; | ||
Auto(String name, int speed) { |
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.
Т.к. сам класс публичный, конструктору тоже лучше прописать модификатор public
src/main/java/Main.java
Outdated
int speed; | ||
while (true) { | ||
System.out.print("Введите скорость машины №" + i + "(от 0 до 250 км/ч): "); | ||
speed = scanner.nextInt(); |
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.
Если ввести символы вместо чисел, то здесь вылетит эксепшн, что экстренно завершит выполнение программы с потерей всех введенных данных
src/main/java/Race.java
Outdated
String leader = ""; | ||
int leaderDistance = 0; |
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.
Эти переменные лучше сделать приватными, а для получения имени победителя написать отдельную функцию-геттер. Это исключит возможность модификации этих переменных извне, тем самым не позволяя ломать поведение этого класса, т.е. он будет защищённее и стабильнее
…а возможность модификации множества переменных извне. Устранена ошибка при вводе символов.
Выполнил Практическую работу №1, это консольное приложение, которое вычисляет лидера в гонке, при помози тех данных, что ввел пользователь - «24 часа Ле-Мана».