-
Notifications
You must be signed in to change notification settings - Fork 0
Проект 1 #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
base: main
Are you sure you want to change the base?
Проект 1 #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,66 @@ | ||
|
|
||
| import java.util.Scanner; | ||
| public class Main { | ||
| String winner=""; | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| int autoSpeed = -1; | ||
| String autoName = ""; | ||
| String finalWinner = ""; | ||
| Auto[] autoList = new Auto[3]; | ||
| Race raceCls = new Race(); | ||
| System.out.println("Welcome to Le-Mans 24"); | ||
| for (int i = 0; i < autoList.length;i++) { | ||
| System.out.println("Введите название автомобиля #" + (i + 1) + ":"); | ||
| autoName = scanner.next(); | ||
|
|
||
| while (true){ | ||
| System.out.println("Укажите скорость автомобиля #" + (i + 1) + ": "); | ||
| if (scanner.hasNextInt()) { | ||
| autoSpeed = scanner.nextInt(); | ||
| if (autoSpeed > 0 && autoSpeed <= 250) { | ||
| break; | ||
| } else { | ||
| System.out.println("Некорректное значение скорости, введите скорость в диапазоне от 0 до 250"); | ||
| } | ||
| } else{ | ||
| System.out.println("Скорость должна быть указв в виде целого числа"); | ||
| scanner.next(); | ||
| } | ||
| } | ||
| autoList[i] = new Auto(autoName,autoSpeed); | ||
| finalWinner = raceCls.setRaceWinner(autoName,autoSpeed,finalWinner); | ||
| } | ||
| /*for (int i=0; i <3; i++){ | ||
|
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.println("Атомобиль "+autoList[i].name +" движется со скоростью "+ autoList[i].speed +" км/ч"); | ||
| } | ||
| */ | ||
| System.out.println("Самый быстрый автомобиль: "+finalWinner); | ||
| } | ||
|
|
||
| } | ||
| class Auto { | ||
| String name; | ||
| int speed; | ||
| public Auto(String autoName,int autoSpeed) { | ||
| this.name = autoName; | ||
| this.speed = autoSpeed; | ||
| } | ||
| } | ||
| class Race{ | ||
|
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. Лучше разнести по разным файлам, так удобнее с точки зрения чтения кода |
||
| //String winner=""; | ||
| int pathLength = 0; | ||
|
|
||
| public String setRaceWinner(String name, int speed,String winner){ | ||
| if (winner.isEmpty()){ //winner.equals("") | ||
| pathLength = 24 * speed; | ||
| winner = name; | ||
| } else { | ||
| int newPathLeng = 24 * speed; | ||
| if (newPathLeng > pathLength){ | ||
| pathLength = newPathLeng; | ||
| winner = name; | ||
| } | ||
| } | ||
| return winner; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В Android студии можно сделать авто форматирование, нажав ПКМ по нужному классу и выбрав
Reformat code, или нажать сочетание клавиш из соответствующего пункта в меню.