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

public class Main {

public static void main(String[] args) {
System.out.println("Hello world!");
Gonka gonka = new Gonka();
gonka.nameAuto();
gonka.spidAuto();
gonka.calculationLeader();
}
}
}

class Gonka {
Comment thread
ITRoRo marked this conversation as resolved.
Scanner scanner = new Scanner(System.in);
Comment thread
ITRoRo marked this conversation as resolved.
Auto cars1 = new Auto();
Auto cars2 = new Auto();
Auto cars3 = new Auto();

public void nameAuto() {
System.out.println("Выбери 3 болида, узнаем кто самый быстрый!");
System.out.println("Первый претендент:");
cars1.name = scanner.next();
System.out.println("Второй претендент:");
cars2.name = scanner.next();
System.out.println("Третий претендент:");
cars3.name = scanner.next();
}

public void spidAuto() {
System.out.println("Какая скорость у болида: " + cars1.name);
while (true) {
while (!scanner.hasNextInt()) {
System.out.println("Введи число, а не вот это все...: ");
scanner.next();
}
cars1.spid = scanner.nextInt();
if (cars1.spid > 250) {
System.out.println("Это автомобиль, а не самолет, введи число поменьше: ");
} else if (cars1.spid < 0) {
System.out.println("Скорость это положительное число: ");
} else {
break;
}
}
System.out.println("Какая скорость у болида: " + cars2.name);
while (true) {
while (!scanner.hasNextInt()) {
System.out.println("Скорость - число");
scanner.next();
}
cars2.spid = scanner.nextInt();
if (cars2.spid > 250) {
System.out.println("Скорость болида до 250 км.ч");
} else if (cars2.spid < 0) {
System.out.println("Скорость это положительное число: ");
} else {
break;
}
}
System.out.println("Какая скорость у болида: " + cars3.name);
while (true) {
while (!scanner.hasNextInt()) {
System.out.println("Неврно, напиши число: ");
scanner.next();
}
cars3.spid = scanner.nextInt();
if (cars3.spid > 250) {
System.out.println("Пошел на взлет...\nВведи число поменьше: ");
} else if (cars3.spid < 0) {
System.out.println("Скорость это положительное число: ");
} else {
break;
}
Comment thread
ITRoRo marked this conversation as resolved.
}
}

public void calculationLeader() {
ArrayList<Integer> autoList = new ArrayList<>();
int сmileageСars1 = cars1.spid * 24;
int сmileageСars2 = cars2.spid * 24;
int сmileageСars3 = cars3.spid * 24;
autoList.add(сmileageСars1);
autoList.add(сmileageСars2);
autoList.add(сmileageСars3);
int maxCmileage = autoList.get(0);
int n = autoList.size();
for (int i = 1; i < n; i++)
if (autoList.get(i) > maxCmileage) {
maxCmileage = autoList.get(i);
}
if (сmileageСars1 == maxCmileage) {
System.out.println("Победил " + cars1.name + " ,проехав " + maxCmileage + " киллометров!");
}
if (сmileageСars2 == maxCmileage) {
System.out.println("Победил " + cars2.name + " ,проехав " + maxCmileage + " киллометров!");
}
if (сmileageСars3 == maxCmileage) {
System.out.println("Победил " + cars3.name + " ,проехав " + maxCmileage + " киллометров!");
}
}
}

class Auto {
String name;
int spid;
}