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

ПР 2 #385

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
FaaLiK wants to merge 1 commit into Yandex-Practicum:main
base: main
Choose a base branch
Loading
from FaaLiK: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
2 changes: 1 addition & 1 deletion README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Пустой репозиторий для работы с Java кодом в Android Studio
24 часа Ле-Мана
18 changes: 18 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,18 @@
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;
}
public int mileage() {
return 24 * speed;
}
}
48 changes: 44 additions & 4 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
public static void main(String[] args){
System.out.println("24 часа Ле-Мана");
Scanner scanner = new Scanner(System.in);
Car[] cars = new Car[3];
Race race = new Race();

for (int i = 0; i < cars.length; i++) {
System.out.println("Автомобиль " + (i + 1) + ":");

String name;
while (true) {
System.out.println("Введите название автомобиля: ");
name = scanner.nextLine().trim();
if(!name.isEmpty()){
break;
}
System.out.println("Ошибка: название автомобиля не может быть пустым!");
}

int speed = 0;
while (true) {
System.out.println("Введите скорость автомобиля (1-250 км/ч): ");
if (scanner.hasNextInt()) {
speed = scanner.nextInt();
scanner.nextLine();
if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Скорость должна быть от 1 до 250.");
}
} else {
System.out.println("Введите целое число");
scanner.next();
}
}

cars[i] = new Car(name, speed);
}
}

Car winner = race.raceWinner(cars);
System.out.println("Самая быстрая машина: " + winner.getName());
}
}

15 changes: 15 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,15 @@
public class Race {
public Car raceWinner(Car[] cars) {
Car winner = cars[0];
int maxDistance = cars[0].mileage();
for (int i = 1; i < cars.length; i++) {
int currentDistance = cars[i].mileage();
if (currentDistance > maxDistance) {
maxDistance = currentDistance;
winner = cars[i];
}
}
return winner;
}
}

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