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/Automobile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Automobile {
int speed;
String name;

public Automobile(String name, int speed){
this.name = name;
this.speed = speed;
}
}
33 changes: 32 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
import java.util.Scanner;

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

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

for (int i = 1; i <= 3; i++){
System.out.printf("Введите название машины №%d%n", i);
name = scanner.next();

while (true){
System.out.printf("Введите скорость машины №%d%n", i);

if (scanner.hasNextInt())
speed = scanner.nextInt();
else{
System.out.println("Неправильная скорость");
scanner = new Scanner(System.in);
continue;
}

if (speed <= 0 || speed > 250)
System.out.println("Неправильная скорость");
else
break;
}

race.checkLeader(new Automobile(name, speed));
}

System.out.printf("Самая быстрая машина: %s%n", race.raceLeader);
}
}
15 changes: 15 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Race {
final int time = 24;
int leaderDistance = 0;
public String raceLeader = "";

public void checkLeader(Automobile automobile){
int automobileDistance = automobile.speed * time;

if (automobileDistance > leaderDistance)
{
leaderDistance = automobileDistance;
raceLeader = automobile.name;
}
}
}