-
Notifications
You must be signed in to change notification settings - Fork 0
df #1
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?
df #1
Changes from all commits
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 |
|---|---|---|
| @@ -1,6 +1,62 @@ | ||
| 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(); | ||
|
|
||
| int numberOfCars = 3; | ||
|
|
||
|
|
||
| for (int i = 0; i < numberOfCars; i++) { | ||
| System.out.println("— Введите название машины №" + (i + 1) + ":"); | ||
| String name = scanner.nextLine(); | ||
|
|
||
| int speed; | ||
| while (true) { | ||
| System.out.println("— Введите скорость машины №" + (i + 1) + ":"); | ||
| if (scanner.hasNextInt()) { | ||
| speed = scanner.nextInt(); | ||
| scanner.nextLine(); | ||
| int minSpeed = 0; | ||
| int maxSpeed = 250; | ||
| if (speed > minSpeed && speed <= maxSpeed) { | ||
| break; | ||
| } else { | ||
| System.out.println("— Неправильная скорость"); | ||
| } | ||
| } | ||
| } | ||
| Auto car = new Auto(name, speed); | ||
| race.checkNewLeader(car); | ||
| } | ||
| System.out.println("Самая быстрая машина: " + race.leader); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class Auto { | ||
| String name; | ||
| int speed; | ||
|
Comment on lines
+39
to
+40
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. Поля лучше пометить |
||
|
|
||
| Auto(String name, int speed) { | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class Race { | ||
| String leader = ""; | ||
| int distance = 0; | ||
|
Comment on lines
+50
to
+51
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. Эти два поля лучше пометить |
||
|
|
||
| void checkNewLeader( Auto car) { | ||
| int time = 24; | ||
| int carDistance = time * car.speed; | ||
|
|
||
| if (carDistance > distance) { | ||
| distance = carDistance; | ||
| leader = car.name; | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода