Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Создание консольного приложения#1

Open
AleksandrPolistsuk wants to merge 3 commits intomain from
dev
Open

Создание консольного приложения #1
AleksandrPolistsuk wants to merge 3 commits intomain from
dev

Conversation

@AleksandrPolistsuk
Copy link
Owner

@AleksandrPolistsuk AleksandrPolistsuk commented Sep 18, 2024

Создание консольного приложения для поиска победителя гонок после ввода данных.

Comment on lines 5 to +8
public static void main(String[] args) {
System.out.println("Hello world!");
CarRace carRaces = new CarRace();
carRaces.start();
carRaces.displayWinner();
Copy link

Choose a reason for hiding this comment

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

Нет особого смысла выносить абсолютно всё из main. В твоём случае CarRace это God Object.


class CarRace {
Scanner scanner = new Scanner(System.in);
ArrayList <Car> carList = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

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

ArrayList это имплементация интерфейса List. Правильнее будет объявить так:

List<Car> carList = new ArrayList()

Comment on lines 43 to 64
for (int i=1;i<=3;i++){
System.out.println("Введите название автомобиля номер " +i +":");
String nameCar = scanner.nextLine();
int speedCar;
while (true){
System.out.println("Введите скорость (от 0 до 250) автомобиля номер " +i +":");
speedCar = Integer.parseInt(scanner.nextLine());
if (speedCar >= 0 && speedCar <= 250) {
break;
} else {
System.out.println("Скорость должна быть в диапазоне от 0 до 250. Попробуйте снова.");

}}

carList.add(new Car(nameCar, speedCar));
distance(nameCar, speedCar);
}

scanner.close();

}
}
Copy link

Choose a reason for hiding this comment

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

Всё очень грустно с индентацией(пробелами в начале строк). Тяжело читать такой код, нужно поправить.

Comment on lines +69 to +70
String name;
int speed;
Copy link

Choose a reason for hiding this comment

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

В Джаве принято делать поля приватным и писать для них геттеры и сеттеры.

Copy link
Owner Author

@AleksandrPolistsuk AleksandrPolistsuk Sep 19, 2024

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

Reviewers

1 more reviewer

@kekulta kekulta kekulta left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /