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

пр1.1 #295

Open
wants to merge 1 commit 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
9 changes: 9 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Car {
public String name; // Название автомобиля
public int speed; // Скорость автомобиля


public Car(String name, int speed) {
this.name = name;
this.speed = speed;}
}
24 changes: 23 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
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.print("Введите название машины №" + i + ": ");
String name = scanner.next();

int speed;
while (true) {
System.out.print("Введите скорость машины №" + i + ": ");
speed = scanner.nextInt();
if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Неправильная скорость. Пожалуйста, введите скорость от 1 до 250.");
}
}
Car car = new Car(name, speed);
race.determineNewLeader(car);
}
System.out.println("Самая быстрая машина: " + race.getCurrentLeader());
scanner.close();
}
}
17 changes: 17 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Race {
String currentLeader = ""; // Текущий лидер гонки
int leaderDistant = 0; // Дистанция, пройденная текущим лидером

public void determineNewLeader(Car car) {
int timeRace = 24;
int newDistance = timeRace * car.speed;

if (newDistance > leaderDistant) {
currentLeader = car.name;
leaderDistant = newDistance;
}
}
public String getCurrentLeader() {
return currentLeader;
}
}