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

как все успеть? #408

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
R1ftborn wants to merge 1 commit into Yandex-Practicum:dev
base: dev
Choose a base branch
Loading
from R1ftborn: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
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;
}
}

53 changes: 52 additions & 1 deletion src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
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 + ":");


System.out.print("Название автомобиля: ");
String carName = scanner.nextLine().trim();


while (carName.isEmpty()) {
System.out.println("Название автомобиля не может быть пустым!");
System.out.print("Название автомобиля: ");
carName = scanner.nextLine().trim();
}

int speed = 0;
boolean validSpeed = false;

while (!validSpeed) {
System.out.print("Скорость автомобиля (км/ч, от 1 до 250): ");

if (scanner.hasNextInt()) {
speed = scanner.nextInt();
scanner.nextLine();

if (speed > 0 && speed <= 250) {
validSpeed = true;
} else {
System.out.println("Скорость должна быть больше 0 и не больше 250 км/ч!");
}
} else {
System.out.println("Введите целое число!");
scanner.nextLine();
}
}

Car car = new Car(carName, speed);
race.determineLeader(car);

System.out.println();
}


String winner = race.getWinner();
if (!winner.isEmpty()) {
System.out.println("Самая быстрая машина: " + winner);
}

scanner.close();
}
}
20 changes: 20 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,20 @@
public class Race {
private String leaderName = "";
private int leaderDistance = 0;

public void determineLeader(Car car) {
int distance = 24 * car.getSpeed();

if (distance > leaderDistance) {
leaderName = car.getName();
leaderDistance = distance;
}
}

public String getWinner() {
return leaderName;
}
}



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