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
# Не пустой репозиторий для работы с Java кодом в Android Studio
11 changes: 9 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
//System.out.println("Hello world!");
Race drive = new Race();
drive.start();


}
}
}

66 changes: 66 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import static java.lang.Character.isDigit;

import java.util.ArrayList;
import java.util.Scanner;

public class Race {
ArrayList<automobile> MembersRace = new ArrayList<>();
Scanner scanner = new Scanner(System.in);

// Ввод имени
public String InputName() {

while (true) {
System.out.println("— Введите название машины №" + (MembersRace.size() + 1));
String input = scanner.nextLine();

if ((!(input == null)) & (!input.isEmpty())) {
return input;
} else {
System.out.println("— Неправильная наименование ");
}
}
}

//Ввод скорости
public int InputSpeed() {
while (true) {
System.out.println("— Введите скорость машины №" + (MembersRace.size() + 1));
String input = (scanner.nextLine());

boolean isDigit=!(input.isEmpty());
for (int i=0;i<input.length();i++){
isDigit=isDigit & isDigit(input.charAt(i));
}
if (!isDigit) {
;
}
else if ((Integer.parseInt(input) <= 250) & (Integer.parseInt(input) > 0)) {
return Integer.parseInt(input);
}
System.out.println("— Неправильная скорость ");

}
}


//Запуск приложения
public void start() {
for (int i = 0; i < 3; i++) {
MembersRace.add(new automobile(InputName(), InputSpeed()));
}
LeaderCalculation (MembersRace);
}

// Вычисление лидера
public void LeaderCalculation(ArrayList<automobile> MembersRace) {
automobile leader = new automobile("", 0);
for (automobile car : MembersRace) {
if (leader.Speed < car.Speed) {
leader = car;
}
}
System.out.println("Самая быстрая машина: " + leader.Name);

}
}
12 changes: 12 additions & 0 deletions src/main/java/automobile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import java.util.ArrayList;

public class automobile {
int Speed;
String Name;

public automobile(String Name, int Speed) {
this.Name = Name;
this.Speed = Speed;
}
}