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
57 changes: 55 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@


import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
HashMap<String, Integer> autoMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
System.out.println("Введите название: ");
String name = scanner.next();
o:
while (true) {
int speed;
System.out.println("Введите скорость: ");
if (scanner.hasNextInt()) {
speed = scanner.nextInt();

if (Races.speedLimit(speed)) {
autoMap.put(name, speed);
break o;
} else {
System.out.println("Неправильная скорость");


}

} else {
System.out.println("Неправильное значение");
scanner.next();
}


}
}
System.out.println(autoMap);
List<Integer> l = autoMap.values().stream().sorted().toList();
Integer lMax = l.get(l.size() - 1);
String autoSpeedMax = "";


for (Map.Entry<String, Integer> entry : autoMap.entrySet()) {
if (Objects.equals(entry.getValue(), lMax)) {
autoSpeedMax = entry.getKey();

}
}
System.out.println("Самая быстрая машина: " + autoSpeedMax);

}
}
}

11 changes: 11 additions & 0 deletions src/main/java/Races.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Races {
String name;
int speed;
Races(String name, int speed){
this.name=name;
this.speed=speed;
}
static boolean speedLimit(int speed){
return speed <= 250 && speed > 0;
}
}