Repository navigation
уцй #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
shadowbulletzz
wants to merge
2
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
уцй #1
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,17 @@ | ||
| public class Car { | ||
| private final String name; | ||
| private final int speed; | ||
|
|
||
| public Car(String name, int speed){ | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
|
|
||
| public String gName(){ | ||
| return name; | ||
| } | ||
|
|
||
| public int gSpeed(){ | ||
| return speed; | ||
| } | ||
| } | ||
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,35 @@ | ||
|
|
||
| import java.util.List; | ||
| import java.util.Scanner; | ||
| import java.util.ArrayList; | ||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| } | ||
| } | ||
| public static void main(String[] args){ | ||
|
shadowbulletzz marked this conversation as resolved.
|
||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("Добро пожаловать в самую реалистичную гонку во вселенной"); | ||
|
|
||
| List<Car> cars = new ArrayList<>(); | ||
| for (int i = 0; i < 3; i++){ | ||
| System.out.println("Укажи название автомобиля " + (i+1) + " "); | ||
| String name = scanner.nextLine().trim(); | ||
|
|
||
| System.out.println("Укажи скорость автомобиля " + (i+1) + " " ); | ||
| int speed; | ||
| do { | ||
| try { | ||
| speed = Integer.parseInt(scanner.nextLine().trim()); | ||
| if (speed >= 0 && speed <= 250) { | ||
| break; | ||
| } else { | ||
| System.out.println("Неправильно указал скорость. Введи число от 1 до 250"); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Неправильно написал. Нужно указать число от 1 до 250"); | ||
| } | ||
| } while (true); | ||
|
|
||
| cars.add(new Car(name, speed)); | ||
| } | ||
| Race race = new Race(cars); | ||
| race.printLeadInfo(); | ||
| } | ||
|
|
||
| } | ||
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,32 @@ | ||
| import java.util.List; | ||
|
|
||
| public class Race { | ||
| private List<Car> cars; | ||
|
|
||
| public Race(List<Car> cars) { | ||
| this.cars = cars; | ||
| } | ||
|
|
||
| public Car fWin() { | ||
| double mDistant = 0; | ||
| Car win = null; | ||
|
|
||
| for (Car car : cars) { | ||
| double distan = calcDistanc(car); | ||
| if (distan > mDistant){ | ||
| mDistant = distan; | ||
| win = car; | ||
| } | ||
| } | ||
|
|
||
| return win; | ||
| } | ||
|
|
||
| private double calcDistanc(Car car) { | ||
| return car.gSpeed() * 24; | ||
| } | ||
| public void printLeadInfo() { | ||
| Car win = fWin(); | ||
| System.out.printf("Самая быстрая машина: %s, прошла %,.2f км за 24 часа.\n", win.gName(), calcDistanc(win)); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.