-
Notifications
You must be signed in to change notification settings - Fork 0
Pull request from dev to main #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f18f480
dc248da
583400d
10b3e81
55e230a
da72d0d
462ba23
a9597cd
dc3892f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class Car { | ||
| String name; | ||
| int speed; | ||
|
|
||
| public Car(String name, int speed) { | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,57 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| Race race = new Race(); | ||
|
|
||
| for (int i = 1; i <= 3; i++) { | ||
| //Работа с наименованием | ||
| String carName = ""; | ||
| while (true) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не рекомендую писать бесконечные циклы через |
||
| System.out.println(" - Введите название машины № " + i); | ||
| carName = scanner.nextLine(); | ||
| if (carName.isBlank()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать |
||
| System.out.println("Вы не ввели название машины!"); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| //Работа со скоростью | ||
| int speed; | ||
| while (true) { | ||
| System.out.println(" - Введите скорость машины № " + i); | ||
| String input = scanner.nextLine(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Код для считывания скорости с ввода лучше вынести в отдельную функцию аналогично |
||
|
|
||
| if (input.isBlank()) { | ||
| System.out.println("Вы ввели пустую строчку!"); | ||
| continue; | ||
| } | ||
| try { | ||
| speed = Integer.parseInt(input); | ||
| if (speed <= 250 && speed > 0) { | ||
FiLbI4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| } else { | ||
| System.out.println("Введена некорректная скорость! Введите скорость из диапазона от 0 до 250"); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Введите целое число!"); | ||
| } | ||
| } | ||
| Car car = new Car(carName, speed); | ||
| race.getDistation(car); | ||
| } | ||
| scanner.close(); | ||
| System.out.println("Самая быстрая машина: " + race.leader); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Race { | ||
| String leader = ""; | ||
| int leaderDistance = 0; | ||
| int time = 24; | ||
| public void getDistation(Car newCar) { | ||
| int distance = time * newCar.speed; | ||
| if (distance > leaderDistance) { | ||
| leader = newCar.name; | ||
| leaderDistance = distance; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
Uh oh!
There was an error while loading. Please reload this page.