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

Практ. задание #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
morfleno wants to merge 2 commits into master
base: master
Choose a base branch
Loading
from new
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
3 changes: 3 additions & 0 deletions .idea/.gitignore
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml
View file Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/main/java/Car.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Car {
private String name;
private int speed;

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

public String getName() {
return name;
}

public int getSpeed() {
return speed;
}

public void setName(String name) {
this.name = name;
}

public void setSpeed(int speed) {
this.speed = speed;
}
}
38 changes: 34 additions & 4 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
public class Main {
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
Scanner scanner = new Scanner(System.in);
Car[] cars = new Car[3];

for (int i = 0; i < 3; i++) {
System.out.println("Введите название автомобиля " + (i + 1) + ":");
String name = scanner.nextLine();

int speed = 0;
while (true) {
System.out.println("Введите скорость автомобиля " + (i + 1) + " (0 < скорость ⩽ 250):");
try {
speed = scanner.nextInt();
scanner.nextLine();
if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Неправильная скорость. Попробуйте еще раз.");
}
} catch (InputMismatchException e) {
System.out.println("Неверный ввод, введите число.");
scanner.nextLine();
}
}

cars[i] = new Car(name, speed);
}

Race race = new Race();
Car winner = race.determineWinner(cars);

System.out.println("Самая быстрая машина: " + winner.getName());
}
}
15 changes: 15 additions & 0 deletions src/main/java/Race.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Race {
public Car determineWinner(Car[] cars) {
Car winner = null;
int maxDistance = 0;

for (Car car : cars) {
int distance = car.getSpeed() * 24;
if (distance > maxDistance) {
maxDistance = distance;
winner = car;
}
}
return winner;
}
}

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