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 #410

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
Felisk0 wants to merge 2 commits into Yandex-Practicum:dev
base: dev
Choose a base branch
Loading
from Felisk0:dev
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: 2 additions & 1 deletion README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Пустой репозиторий для работы с Java кодом в Android Studio
# Программа "Гонки Ле-Ман"
Добавлены классы Car, Race и Main
18 changes: 18 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,18 @@
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;
}
}

25 changes: 24 additions & 1 deletion src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
Race race = new Race();
for(int i = 1; i <= 3; i++) {
System.out.println("Введите название машины No" + i + ":");
String name = scanner.next();

int speed;
while (true) {
System.out.println("Введите скорость машины No" + i + ":");
speed = scanner.nextInt();

if (speed > 0 && speed <= 250) {
break;
} else {
System.out.println("Неправильная скорость");
}
}
Car car = new Car(name, speed);
race.checkLeader(car);
}
System.out.println("Самая быстрая машина: " + race.getLeaderName());
scanner.close();
}
}
16 changes: 16 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,16 @@
public class Race {
private String leaderName = "";
private int bestDistance = 0;

public void checkLeader(Car car) {
int distance = 24 *car.getSpeed();
if (distance > bestDistance) {
leaderName = car.getName();
bestDistance = distance;
}
}

public String getLeaderName() {
return leaderName;
}
}

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