-
Notifications
You must be signed in to change notification settings - Fork 964
Проектная работа No1 #372
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
Проектная работа No1 #372
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
15 changes: 15 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,15 @@ | ||
| public class Car { | ||
| public int speed; | ||
| public String name; | ||
|
|
||
| public Car(String name,int speed) { | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
46 changes: 45 additions & 1 deletion
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,50 @@ | ||
| 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 = 1; i <= 3; i++) { | ||
| String name; | ||
| while (true) { | ||
| System.out.println("Введите название автомобиля No " + i); | ||
| name = scanner.nextLine(); | ||
|
|
||
| if (!name.isEmpty()) { | ||
| break; | ||
|
|
||
| } else { | ||
| System.out.println("Название не должно быть пустым"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| int speed; | ||
| while (true) { | ||
| System.out.println("Введите скорость автомобиля в диапазоне от 0 до 250 км/ч"); | ||
|
|
||
| if (scanner.hasNextInt()) { | ||
| speed = scanner.nextInt(); | ||
| scanner.nextLine(); | ||
| if (speed >= 0 && speed <= 250) { | ||
| break; | ||
| } else { | ||
| System.out.println("Введите корректное значение"); | ||
| } | ||
| } else { | ||
| System.out.println("Введите корректное значение"); | ||
| scanner.next(); | ||
| } | ||
| } | ||
|
|
||
| Car car = new Car(name, speed); | ||
|
|
||
| race.checkWinner(car); | ||
|
|
||
| } | ||
| System.out.println("Самая быстрая машина: " + race.getWinner()); | ||
| scanner.close(); | ||
|
|
||
| } | ||
| } |
19 changes: 19 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,19 @@ | ||
| public class Race { | ||
| String winner = ""; | ||
| int winnerDistance = 0; | ||
|
|
||
| public void checkWinner(Car car) { | ||
| int distance = car.speed * 24; | ||
|
|
||
| if (distance > winnerDistance) { | ||
| winner = car.name; | ||
| winnerDistance = distance; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| String getWinner() { | ||
| 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.