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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Пустой репозиторий для работы с Java кодом в Android Studio
# 24 часа Ле-Мана
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 {
static String name;
static int speed;

public Car(String name, int speed) {
this.name = name;
this.speed = speed;
}
}
31 changes: 29 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
ArrayList<Car> carList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
System.out.println("Введите название машины № " + i);
String name = scanner.next();
System.out.println("Введите скорость машины № " + i + " в пределах от 0 до 250");
int speed = 0;
while (true) {
try {
speed = scanner.nextInt();
if (speed >= 0 && speed <= 250) {
break;
} else {
System.out.println("Введите скорость машины в пределах от 0 до 250");
}
} catch (InputMismatchException e) {
System.out.println("Некорректный ввод скорости. Введите целое число от 0 до 250");
scanner.next();
}
}
carList.add(new Car(name, speed));
Race.race();
}
scanner.close();
System.out.println("Самая быстрая машина: " + Race.leader);
}
}
}
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 {
public static String leader = "";
static int distance = 0;

public static void race() {
int newDistance = (24 * Car.speed);
if (newDistance > distance) {
leader = Car.name;
distance = newDistance;
}
}
}