Skip to content

Conversation

@AleksandrPolistsuk
Copy link
Owner

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

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

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.

3 participants