Skip to content
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
51 changes: 50 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");

Scanner in = new Scanner(System.in);
Race currentRace = new Race();
int carSpeed;

for (int i = 1; i < 4; i++) {
System.out.println("— Введите название машины № " + i);
String carName = in.next();
System.out.println("— Введите скорость машины № " + i);

while (!in.hasNextInt()) {
System.out.println("— Неправильная скорость");
System.out.println("— Введите скорость машины № " + i);
in.next();
}
carSpeed = in.nextInt();

while (carSpeed < 0 || carSpeed > 250) {
System.out.println("— Неправильная скорость");
System.out.println("— Введите скорость машины № " + i);
carSpeed = in.nextInt();
}

Car currentCar = new Car(carName, carSpeed);
currentRace.setLeader(currentCar);
}
System.out.println("Самая быстрая машина: " + currentRace.leader.name);
}
}

class Car {
String name;
int speed;

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

class Race {
Car leader;
int distance = 0;
public void setLeader (Car currentCar) {
if (distance < currentCar.speed*24) {
distance = currentCar.speed*24;
leader = currentCar;
}
}

}