From 6370482e4f42cf10fb1022d4b6e4f43f3cc8e6cf Mon Sep 17 00:00:00 2001 From: IFeelLikeGod Date: Tue, 30 Dec 2025 21:03:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 62 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index db9356a08..1fec73783 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,6 +1,64 @@ +import java.util.Scanner; public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + Scanner scanner = new Scanner(System.in); + int n = 3; + + + Car[] cars = new Car[n]; + + for (int i = 0; i < n; i++) { + System.out.println("Введите название машины №" + (i + 1) + ":"); + String name = scanner.nextLine(); + + double velocity; + while (true) { + System.out.println("— Введите скорость машины №" + (i + 1) + ":"); + velocity = scanner.nextDouble(); + scanner.nextLine(); + + if (velocity >= 0 && velocity <= 250) break; + System.out.println("Неправильная скорость"); + } + + cars[i] = new Car(name, velocity); + } + + Car winner = Race.winner(cars); + + if (winner == null) { + System.out.println("Нет машин с допустимой скоростью (0..250)."); + } else { + System.out.println("Самый быстрый автомобиль: " + winner.name); + + } + + scanner.close(); + } +} + +class Car { + String name; + double velocity; + + Car(String name, double velocity) { + this.name = name; + this.velocity = velocity; + } +} + +class Race { + static Car winner(Car[] cars) { + Car winner = null; + + for (Car c : cars) { + if (c.velocity >= 0 && c.velocity <= 250) { + if (winner == null || c.velocity * 24 > winner.velocity * 24) { + winner = c; + } + } + } + return winner; } -} \ No newline at end of file +}