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
9 changes: 9 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Car {
String brand;
int speed;

public Car(String brand, int speed) {
this.brand = brand;
this.speed = speed;
}
}
39 changes: 38 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
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++) {

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

int speed = 0;
while (true) {
System.out.println("Введите скорость машины №" + i + ":");
if (!scanner.hasNextInt()) {
System.out.println("Неправильная скорость");
scanner.nextLine();
continue;
}
speed = scanner.nextInt();
scanner.nextLine();
if (speed > 0 && speed <= 250) {
break;
}
System.out.println("Неправильная скорость");
}


Car car = new Car(brand, speed);
race.checkLeader(car);
}

System.out.println("Самая быстрая машина: " + race.leader);
scanner.close();
}
}
12 changes: 12 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Race {
String leader = "";
int leaderDistance = 0;

public void checkLeader(Car car) {
int distance = car.speed * 24;
if (distance > leaderDistance) {
leader = car.brand;
leaderDistance = distance;
}
}
}