Repository navigation
Создание консольного приложения - #1
Open
AleksandrPolistsuk wants to merge 3 commits into
Open
AleksandrPolistsuk wants to merge 3 commits into
AleksandrPolistsuk wants to merge 3 commits into
Conversation
kekulta
reviewed
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(); |
There was a problem hiding this comment.
Нет особого смысла выносить абсолютно всё из main. В твоём случае CarRace это God Object.
|
|
||
| class CarRace { | ||
| Scanner scanner = new Scanner(System.in); | ||
| ArrayList <Car> carList = new ArrayList<>(); |
There was a problem hiding this comment.
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(); | ||
|
|
||
| } | ||
| } |
There was a problem hiding this comment.
Всё очень грустно с индентацией(пробелами в начале строк). Тяжело читать такой код, нужно поправить.
Comment on lines
+69
to
+70
| String name; | ||
| int speed; |
There was a problem hiding this comment.
В Джаве принято делать поля приватным и писать для них геттеры и сеттеры.
Owner
Author
There was a problem hiding this comment.
пока не проходили это, но изучу
… при вводе букв или не целого числа, выводится сообщение об ошибке и просит новый ввод.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Создание консольного приложения для поиска победителя гонок после ввода данных.