Skip to content

add logic for calculating race winner - #1

Open
matissiyaEdu wants to merge 1 commit into
devfrom
task-1
Open

matissiyaEdu wants to merge 1 commit into
devfrom
task-1

Conversation

@matissiyaEdu

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main/java/Car.java
Comment on lines +4 to +5
private final String name;
private final 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

Comment thread src/main/java/Car.java
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Car car = (Car) o;
return Objects.equals(getName(), car.getName());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ожидаемо, что помимо названия для сравнения объектов будет также использоваться скорость

private static final int CARS_LIMIT = 3;

Scanner scanner = new Scanner(System.in);
Set<Car> cars = new HashSet<>();

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