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

main #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
Tr1ad0s wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from dev
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: 76 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,81 @@
import java.util.Scanner;
import java.util.SimpleTimeZone;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
String logotype = """
________ \s
___ __ \\_____ ___________ \s
__ /_/ / __ `/ ___/ _ \\ \s
_ _, _// /_/ // /__ / __/ \s
/_/ |_| \\__,_/ \\___/ \\___/ \s
""";
System.out.println(logotype);
System.out.println("[+]===================[- Race -]======================[+]");
System.out.println("[~] Добро пожаловать в гонки!");
System.out.println("[>] Вам нужно ввести названия 3-х автомобилей и их скорость");
System.out.println("[>] Допустимая скорость от 1 до 250 км/ч");
System.out.println("[~] После мы произведем магию вычисления и определим победителя. Удачи!");
System.out.println("[+]===================[- Race -]======================[+]");

Scanner scanner = new Scanner(System.in);
Race race = new Race();

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

int speed = -1;
while (speed < 0 || speed > 250) {
Copy link

Choose a reason for hiding this comment

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

Здесь лучше так же давать сообщение об ошибке, чтобы пользователь сразу понимал что пошло не так

System.out.print("Теперь его скорость: ");
speed = scanner.nextInt();

if (speed < 0 || speed > 250) {
System.out.println("[-]: Скорость должна быть от 1 до 250");
}
}

Car car = new Car(nameCar, speed);
race.whoLeader(car);
}

System.out.println("Победитель гонки: " + race.getThatLeader());
scanner.close();
}
}

class Car {
String nameCar;
int speed;

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

public String getNameCar(){
return nameCar;
}

public int getSpeed() {
return speed;
}
}

class Race {
String leader = "";
int distansLeader = 0;
Comment on lines +66 to +67
Copy link

Choose a reason for hiding this comment

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

Правильно, что сделал геттер и не обращаешься к переменной напрямую, но так же было бы неплохо сделать их приватными.


public void whoLeader(Car Car) {
Copy link

Choose a reason for hiding this comment

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

Больше подошло бы название addNewCar или что-то в таком духе

int distant = 24 * Car.getSpeed();

if (distant > distansLeader){
leader = Car.getNameCar();
distansLeader = distant;
}
}

public String getThatLeader() {
return leader;
}
}

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