Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Проектная работа No1 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
novinnik wants to merge 2 commits into main
base: main
Choose a base branch
Loading
from dev_main
Open
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
77 changes: 75 additions & 2 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
System.out.println("Hello world!");
System.out.println("24 часа Ле-мана");

Scanner scanner = new Scanner(System.in);

for (int i = 0; i < 3; i++) {
int numberAuto = i + 1;

String nameAuto;

while (true) {
System.out.println(" - Введите наименование авто No" + numberAuto);
String nameStr = scanner.next();
if (!nameStr.isEmpty()) {
nameAuto = nameStr;
break;
}
}

int speedAuto;

while (true) {
System.out.println(" - Введите скорость авто (1-250) No" + numberAuto);

if (scanner.hasNextInt()){
speedAuto = scanner.nextInt();
if (speedAuto > 0 && speedAuto <= 250) {
break;
} else {
System.out.println("Указана скорость в неверном диапазоне (1-250)!");
}
} else {
scanner.next();
System.out.println("Значение скорости должно быть цифровым!");
}
}
Car car = new Car(nameAuto, speedAuto);

Race.leader(car);
}
scanner.close();
System.out.println("Самая быстрая машина в гонке: " + Race.getName());
}

}

class Car {
String name;
int speed = 0;

public Car(String name, int speed) {
this.name = name;
this.speed = speed;
}
}

class Race {
static String name = "";
static int distance = 0;

public static void leader(Car newCar) {
int newDistance = 24 * newCar.speed;
if (distance < newDistance) {
distance = newDistance;
name = newCar.name;
} else if (distance == newDistance){
name = name + "; " + newCar.name;
}
//System.out.println("Лидер в гонке: " + name);
}

public static String getName() {
return name;
}
}
}

AltStyle によって変換されたページ (->オリジナル) /