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

Доброго времени суток, ДЗ на проверку #264

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 56 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
System.out.println("Hello world!");
double winnerSpeed = 0;
String winnerName = "";
System.out.println("Добро пожаловать на Леман 24, вам предстоит самим назначить 3х участников заезда и узнать, кто из них сможет забать золото!\nБудьте внимательны, скорость на гоночной трассе не может превышать 250км/ч, но и стоять на месте тоже нельзя");

for (int i = 0; i < 3; i++) {
double speed = 0;
Car car = new Car();
Scanner scanner = new Scanner(System.in);
System.out.println("Введите название автомобиля");
car.carName = scanner.nextLine();
System.out.println("С какой скоростью будет двигаться автомобиль " + car.carName + "?");
car.carSpeed = car.speedTest(speed);
if (winnerSpeed < car.carSpeed) {
winnerSpeed = car.carSpeed;
winnerName = car.carName;
}
System.out.println("Отлично, автомобиль " + car.carName + " ворвался на трассу на скорости " + car.carSpeed + "км/ч");
}
System.out.println("Автомобиль " + winnerName + " преодолел " + winnerSpeed * 24 + "км, поздравляем его с победой!");
}
}



class Car {
String carName;
double carSpeed;

// Метод для проверки допустимого значения скорости
double speedTest(double speed) {
Scanner isDouble = new Scanner(System.in);
while (speed == 0) {
if (isDouble.hasNextDouble()) {
speed = isDouble.nextDouble();
if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Значение скорости не подходит для этой трассы");
}
} else {
System.out.println("Некорректное значение скорости");
isDouble.next();
}
speed = 0;
}
return speed;
}
}
}