Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Первый проект! #401

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

Open
AbelMirzayev wants to merge 3 commits into Yandex-Practicum:dev
base: dev
Choose a base branch
Loading
from AbelMirzayev:dev
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
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Car {
private String name;
private int speed;

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

public String getName() {
return this.name;
}

public int getSpeed() {
return this.speed;
}
}
45 changes: 42 additions & 3 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@

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();

System.out.println("Старт гонки 24 часа Ле-Мана!");

int numCars = 3;
for (int i = 1; i <= numCars; i++) {
System.out.println(" Ввод данных для автомобиля:" + i);
System.out.print("Введите название автомобиля: ");
String carName = scanner.next();

int carSpeed = 0;
while (true) {
System.out.print("Введите скорость (от 0 до 250 км/ч): ");

if (scanner.hasNextInt()) {
int inputSpeed = scanner.nextInt();

if (inputSpeed >= 0 && inputSpeed <= 250) {
carSpeed = inputSpeed;
break;
} else {
System.out.println("Ошибка: Скорость должна быть от 0 до 250. Попробуйте снова.");
}
} else {
System.out.println("Ошибка: Введите корректное целое число.");
scanner.next();
}
}
Car newCar = new Car(carName, carSpeed);
race.Leader(newCar);
}
System.out.println("Финиш! Результаты гонки: -");
System.out.println("Самая быстрая машина : " + race.getLeader());

scanner.close();
}
}
}




19 changes: 19 additions & 0 deletions src/main/java/Race.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Race {
String leader = "";
int maxDistance = 0;

public final int RACE_HOURS = 24;

public void Leader(Car newCar) {
int newCarDistance = newCar.getSpeed() * RACE_HOURS;

if (newCarDistance > this.maxDistance) {
this.maxDistance = newCarDistance;
this.leader = newCar.getName();
}
}

public String getLeader() {
return leader;
}
}

AltStyle によって変換されたページ (->オリジナル) /