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

Домашние задание гонка #1

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
Warningrobert wants to merge 1 commit into dev
base: dev
Choose a base branch
Loading
from master
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
79 changes: 76 additions & 3 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,81 @@
import java.util.Scanner;
import java.io.*;
import java.util.*;
public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
Race race = new Race();
race.inputParticipants();
race.calculateWinners();
}
}

class Car {

int speed;
String name;
int distance;

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

}

class Race {

ArrayList<Car> participants = new ArrayList<Car>();
ArrayList<Car> sorted = new ArrayList<Car>();


public void inputParticipants() {
Scanner scanner = new Scanner(System.in);
String name;
int speed;

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

System.out.println("Введите название учавствующего номер " + i + ":");
name = scanner.next();
do {

System.out.println("Введите скорость учавствующего номер " + i + " (0-250):");

if (scanner.hasNextInt()) {
speed = scanner.nextInt();
if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Скорость должна быт между 0 и 250.");
}
} else {
System.out.println("Скорость должна быть цифрой.");
scanner.next();
}
} while (true);

Car car = new Car(name, speed);
participants.add(car);
}
}

public void calculateWinners(){

Car leader = new Car("leader", -1);

for (int i = 0; i < 3; i++){
if (leader.distance < participants.get(i).distance) {
leader = participants.get(i);
}


}

System.out.println("Победил " + leader.name);
}



}

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