From 5c6ea55b8f72ad6ceee215abc836b9e5d2809061 Mon Sep 17 00:00:00 2001 From: tehnikr Date: Fri, 15 Nov 2024 21:13:38 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B0=202=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Car.java | 9 +++++++++ src/main/java/Main.java | 25 ++++++++++++++++++++++++- src/main/java/Race.java | 26 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/Car.java create mode 100644 src/main/java/Race.java diff --git a/src/main/java/Car.java b/src/main/java/Car.java new file mode 100644 index 00000000..f6a7b4f3 --- /dev/null +++ b/src/main/java/Car.java @@ -0,0 +1,9 @@ +public class Car { + String brand; + int speed; + + Car (String brand, int speed){ + this.brand = brand; + this.speed = speed; + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index db9356a0..816936ee 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,6 +1,29 @@ +import java.util.ArrayList; +import java.util.Scanner; public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + System.out.println("24 часа Ле-Мана"); + Scanner scanner = new Scanner(System.in); + + int numberOfCars = 3; + Race rs = new Race(); + + for (int i = 0; i0 && speed<=250){ + rs.addCarToRace(new Car(brand,speed)); + break; + } + System.out.println("— Неправильная скорость"); + } + + } + System.out.println("Самая быстрая машина: " + rs.getWinner()); + scanner.close(); } } \ No newline at end of file diff --git a/src/main/java/Race.java b/src/main/java/Race.java new file mode 100644 index 00000000..766a663e --- /dev/null +++ b/src/main/java/Race.java @@ -0,0 +1,26 @@ +import java.util.ArrayList; + +public class Race { + String leaderCarName = ""; + int maxDist = 0; + + ArrayList Cars = new ArrayList<>(); + + void addCarToRace(Car c){ + Cars.add(c); + int newDist = 24*c.speed; + if (newDist>maxDist){ + leaderCarName = c.brand; + maxDist = newDist; + } + } + + String getWinner (){ + return leaderCarName; + } + + int getNumberCarInRace(){ + return Cars.size(); + } + +} \ No newline at end of file From 1ac301e2a36477ac1647e51f999e2c24088a9c07 Mon Sep 17 00:00:00 2001 From: tehnikr Date: Fri, 15 Nov 2024 21:13:58 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B0=202=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 816936ee..80438882 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,4 +1,3 @@ -import java.util.ArrayList; import java.util.Scanner; public class Main { From f9a0bf650358ed9cb590880f65d0c2f28810bc65 Mon Sep 17 00:00:00 2001 From: tehnikr Date: Mon, 18 Nov 2024 17:04:38 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B0=202,=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=D0=BD=D0=B5=D1=81=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Car.java | 4 ++-- src/main/java/Main.java | 21 +++++++++++++-------- src/main/java/Race.java | 7 ------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/Car.java b/src/main/java/Car.java index f6a7b4f3..3bdd6101 100644 --- a/src/main/java/Car.java +++ b/src/main/java/Car.java @@ -1,6 +1,6 @@ public class Car { - String brand; - int speed; + final String brand; + final int speed; Car (String brand, int speed){ this.brand = brand; diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 80438882..fc7fa9fe 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -9,18 +9,23 @@ public static void main(String[] args) { Race rs = new Race(); for (int i = 0; i0 && speed<=250){ - rs.addCarToRace(new Car(brand,speed)); - break; + System.out.println("— Введите скорость машины № " + (i + 1)); + if (scanner.hasNextInt()){ + int speed = scanner.nextInt(); + if (speed>0 && speed<=250){ + rs.addCarToRace(new Car(brand,speed)); + break; + } else { + System.out.println("— Неправильная скорость"); + } + } else { + System.out.println("— Неправильная скорость, не число"); + scanner.next(); } - System.out.println("— Неправильная скорость"); } - } System.out.println("Самая быстрая машина: " + rs.getWinner()); scanner.close(); diff --git a/src/main/java/Race.java b/src/main/java/Race.java index 766a663e..d698fa86 100644 --- a/src/main/java/Race.java +++ b/src/main/java/Race.java @@ -4,10 +4,7 @@ public class Race { String leaderCarName = ""; int maxDist = 0; - ArrayList Cars = new ArrayList<>(); - void addCarToRace(Car c){ - Cars.add(c); int newDist = 24*c.speed; if (newDist>maxDist){ leaderCarName = c.brand; @@ -19,8 +16,4 @@ String getWinner (){ return leaderCarName; } - int getNumberCarInRace(){ - return Cars.size(); - } - } \ No newline at end of file From fb72e190fa2f89e6a95b15c4fb7986b7a217ddb4 Mon Sep 17 00:00:00 2001 From: tehnikr Date: Mon, 18 Nov 2024 17:24:39 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D0=BF=D1=80=D0=B8=D0=BD=D1=82=D0=B0=202,=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=D0=BD=D0=B5=D1=81=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index fc7fa9fe..5e4863c1 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -19,7 +19,7 @@ public static void main(String[] args) { rs.addCarToRace(new Car(brand,speed)); break; } else { - System.out.println("— Неправильная скорость"); + System.out.println("— Неправильная скорость "); } } else { System.out.println("— Неправильная скорость, не число");