Skip to content

Приложение функционирует #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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

HESOYAMSPQK
Copy link
Owner

Выполнил Практическую работу №1, это консольное приложение, которое вычисляет лидера в гонке, при помози тех данных, что ввел пользователь - «24 часа Ле-Мана».

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

Choose a reason for hiding this comment

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

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

public class Auto {
String name;
int speed;
Auto(String name, int speed) {

Choose a reason for hiding this comment

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

Т.к. сам класс публичный, конструктору тоже лучше прописать модификатор public

int speed;
while (true) {
System.out.print("Введите скорость машины №" + i + "(от 0 до 250 км/ч): ");
speed = scanner.nextInt();

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 leader = "";
int leaderDistance = 0;

Choose a reason for hiding this comment

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

Эти переменные лучше сделать приватными, а для получения имени победителя написать отдельную функцию-геттер. Это исключит возможность модификации этих переменных извне, тем самым не позволяя ломать поведение этого класса, т.е. он будет защищённее и стабильнее

…а возможность модификации множества переменных извне. Устранена ошибка при вводе символов.
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