Skip to content
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

DomZad #294

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Car {
private String name;
private int speed;

public Car(String name, int speed) {
this.name = name;
this.speed = speed;
}

public String getName() {
return name;
}

public int getSpeed() {
return speed;
}
}
39 changes: 37 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
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++) {
System.out.println("Введите название автомобиля " + i + ":");
String name = scanner.next();

int speed;

while (true) {
System.out.println("Введите скорость автомобиля " + i + " (от 0 до 250):");
String input = scanner.next();

try {
speed = Integer.parseInt(input);

if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Ошибка: скорость должна быть от 0 до 250. Попробуйте снова.");
}
} catch (NumberFormatException e) {
System.out.println("Ошибка: введите целое число для скорости. Попробуйте снова.");
}
}


Car car = new Car(name, speed);
race.updateLeader(car);
}


System.out.println("Самая быстрая машина: " + race.getLeaderName());
scanner.close();
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Race {
private String leaderName = "";
private int leaderDistance = 0;

public void updateLeader(Car car) {
int distance = car.getSpeed() * 24; // Расчет дистанции
if (distance > leaderDistance) {
leaderDistance = distance;
leaderName = car.getName();
}
}

public String getLeaderName() {
return leaderName;
}
}