Skip to content
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
13 changes: 13 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Car {

String name;
int speed;

public Car() {

this.name = "";
this.speed = 0;

}

}
44 changes: 42 additions & 2 deletions src/main/java/Main.java
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!");

int carsNumber = 3;
int minSpeed = 0;
int maxSpeed = 250;

Race race = new Race();
Car currentCar = new Car();
Scanner scanner = new Scanner(System.in);

for (int i = 0; i < carsNumber; i++){

System.out.println("Введите название машины №" + (i + 1));
currentCar.name = scanner.next();
System.out.println("Введите скорость машины №" + (i + 1));

while (currentCar.speed == 0){

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

currentCar.speed = scanner.nextInt();

if (currentCar.speed <= minSpeed || currentCar.speed > maxSpeed){
System.out.println("Неправильная скорость");
System.out.println("Введите скорость машины №" + (i + 1));
currentCar.speed = 0;
}

}

race.whoIsTheLeader(currentCar);
currentCar.speed = 0;
}

System.out.println("Самая быстрая машина: " + race.currentLider);
scanner.close();

}
}
}
21 changes: 21 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Race {

String currentLider;
int currentMaxDistance;

public Race(){

currentLider = "";
currentMaxDistance = 0;

}

public void whoIsTheLeader(Car cars){

if (24 * cars.speed > currentMaxDistance){
currentMaxDistance = 24 * cars.speed;
currentLider = cars.name;
}

}
}