-
Notifications
You must be signed in to change notification settings - Fork 0
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
main #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Правильно, что сделал геттер и не обращаешься к переменной напрямую, но так же было бы неплохо сделать их приватными. |
||
|
|
||
| public void whoLeader(Car Car) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Больше подошло бы название |
||
| int distant = 24 * Car.getSpeed(); | ||
|
|
||
| if (distant > distansLeader){ | ||
| leader = Car.getNameCar(); | ||
| distansLeader = distant; | ||
| } | ||
| } | ||
|
|
||
| public String getThatLeader() { | ||
| return leader; | ||
| } | ||
| } | ||