Skip to content

Added class Car and Race with new methods and fields. - #1

Open
hashTagChill wants to merge 1 commit into
devfrom
sprint2
Open

hashTagChill wants to merge 1 commit into
devfrom
sprint2

Conversation

@hashTagChill

Copy link
Copy Markdown
Owner

In Main class added logic to work with class Race and Car, to find leader of the race from user input

In Main class added logic to work with class Race and Car, to find leader of the race from user input
Comment thread src/main/java/Main.java
System.out.println("Введите скорость машины №" + i + ":");
try {
speed = Integer.parseInt(scanner.nextLine());
if (speed > 0 && speed <= 250) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/main/java/Main.java
Comment on lines +43 to +44
private String name;
private int speed;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Плюс можно убрать private и удалить геттеры, если ты сделаешь поля final - это будет так же безопасно и лаконично, как с геттерами

Comment thread src/main/java/Main.java
}

for (Car car : cars) {
race.findLeader(car);

Copy link
Copy Markdown

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