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
develop-mdv wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from 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
9 changes: 9 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,9 @@
public class Car {
String name;
int speed;
Comment on lines +2 to +3
Copy link

@ArturNurtdinov ArturNurtdinov Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поля лучше пометить final, тем самым исключив возможность их модификации извне


Car(String name, int speed){
this.name = name;
this.speed = speed;
}
}
31 changes: 30 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,35 @@
import java.util.ArrayList;
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 = 0; i<3;i++){
System.out.println(String.format("Введите название автомобиля No%d", i+1));
String name = scanner.next();
int speed;
while (true) {
System.out.println(String.format("Введите скорость автомобиля No%d", i + 1));
if (scanner.hasNextInt()){
speed = scanner.nextInt();
if (speed>0 && speed<=250) {
Copy link

@ArturNurtdinov ArturNurtdinov Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода

break;
}
else {
System.out.println("Неправильная скорость(от 0 до 250 значение должно быть)");
}
}
else {
System.out.println("Неправильная скорость, должно быть число");
}

}
Car car = new Car(name, speed);
race.leader_cheak(car);

}
System.out.println(String.format("Самая быстрая машина: %s", race.leader.name));
}
}
11 changes: 11 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,11 @@
public class Race {
Car leader = new Car("", 0);
int leader_distance;
Copy link

@ArturNurtdinov ArturNurtdinov Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переменные в Java принято именовать в соответствии с camelCase, лучше переименовать данную переменную

Comment on lines +2 to +3
Copy link

@ArturNurtdinov ArturNurtdinov Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оба поля лучше сделать приватными, а для получения машины-победителя в конце программы написать отдельную функцию-геттер, чтобы данные поля не были доступны всей программе


void leader_cheak(Car pretendent){
if (pretendent.speed > this.leader.speed){
this.leader = pretendent;
this.leader_distance = this.leader.speed*24;
}
}
}

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