-
Notifications
You must be signed in to change notification settings - Fork 964
ПР 2 #385
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
Open
ПР 2 #385
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| # Пустой репозиторий для работы с Java кодом в Android Studio | ||
| 24 часа Ле-Мана |
18 changes: 18 additions & 0 deletions
src/main/java/Car.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| public int mileage() { | ||
| return 24 * speed; | ||
| } | ||
| } |
48 changes: 44 additions & 4 deletions
src/main/java/Main.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,46 @@ | ||
|
|
||
| import java.util.Scanner; | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| public static void main(String[] args){ | ||
| System.out.println("24 часа Ле-Мана"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| Car[] cars = new Car[3]; | ||
| Race race = new Race(); | ||
|
|
||
| for (int i = 0; i < cars.length; i++) { | ||
| System.out.println("Автомобиль " + (i + 1) + ":"); | ||
|
|
||
| String name; | ||
| while (true) { | ||
| System.out.println("Введите название автомобиля: "); | ||
| name = scanner.nextLine().trim(); | ||
| if(!name.isEmpty()){ | ||
| break; | ||
| } | ||
| System.out.println("Ошибка: название автомобиля не может быть пустым!"); | ||
| } | ||
|
|
||
| int speed = 0; | ||
| while (true) { | ||
| System.out.println("Введите скорость автомобиля (1-250 км/ч): "); | ||
| if (scanner.hasNextInt()) { | ||
| speed = scanner.nextInt(); | ||
| scanner.nextLine(); | ||
| if (speed > 0 && speed <= 250) { | ||
| break; | ||
| } else { | ||
| System.out.println("Скорость должна быть от 1 до 250."); | ||
| } | ||
| } else { | ||
| System.out.println("Введите целое число"); | ||
| scanner.next(); | ||
| } | ||
| } | ||
|
|
||
| cars[i] = new Car(name, speed); | ||
| } | ||
| } | ||
|
|
||
| Car winner = race.raceWinner(cars); | ||
| System.out.println("Самая быстрая машина: " + winner.getName()); | ||
| } | ||
| } | ||
|
|
15 changes: 15 additions & 0 deletions
src/main/java/Race.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| public class Race { | ||
| public Car raceWinner(Car[] cars) { | ||
| Car winner = cars[0]; | ||
| int maxDistance = cars[0].mileage(); | ||
| for (int i = 1; i < cars.length; i++) { | ||
| int currentDistance = cars[i].mileage(); | ||
| if (currentDistance > maxDistance) { | ||
| maxDistance = currentDistance; | ||
| winner = cars[i]; | ||
| } | ||
| } | ||
| return winner; | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.