-
Notifications
You must be signed in to change notification settings - Fork 220
Зайнуллин Артур ДЗ - 1. #156
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
83a7216
Init commit
b1c8fcb
Зайнуллин Артур. Домашняя работа.
281ce89
Зайнуллин Артур. Домашняя работа. Исправления.
bd12c1f
Зайнуллин Артур. Домашняя работа. Исправления.
69aceaf
Remove classes
6c22a84
Change project name
03c5a94
Зайнуллин Артур. Домашняя работа.
c16fa45
Зайнуллин Артур. Домашняя работа. Исправления.
4217b83
Зайнуллин Артур. Домашняя работа. Исправления.
7a9b694
Merge pull request #2 from artcitycreativ/main
artcitycreativ 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
Binary file added
bin/main/Race.class
Binary file not shown.
9 changes: 9 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,9 @@ | ||
| public class Car { | ||
| String name; | ||
| int speed; | ||
|
|
||
| Car(String name, int speed){ | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
| } |
28 changes: 25 additions & 3 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,8 +1,30 @@ | ||
| import java.util.Objects; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| static Race race = new Race(); | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| String command = "start"; | ||
|
|
||
| while(true) | ||
| { | ||
| if(Objects.equals(command, "start")) | ||
| { | ||
| if(race.commandStart()) | ||
| { | ||
| command = scanner.nextLine(); | ||
| } | ||
| } else if(Objects.equals(command, "exit")) | ||
| { | ||
| System.out.println("Завершаем работу."); | ||
| break; | ||
| } else { | ||
| System.out.println("Комманда не распознана."); | ||
| command = scanner.nextLine(); | ||
| } | ||
| } | ||
| } | ||
| } |
86 changes: 86 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,86 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Race { | ||
| ArrayList<Car> carList = new ArrayList<>(); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| String leader; | ||
| int distance = 0; | ||
| String command = "start"; | ||
|
|
||
| private void newLeader(String carName,int speed) { | ||
| int distance = 24 * speed; | ||
| if(distance > this.distance) | ||
| { | ||
| this.leader = carName; | ||
| } | ||
| } | ||
| private void rounds() | ||
| { | ||
| for(int i = 1; i <= 3; i++) { | ||
| try { | ||
| Thread.sleep(1000); | ||
| System.out.println(i + "й круг пройден!"); | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
| public boolean commandStart() | ||
| { | ||
| if(carList.isEmpty()) | ||
| { | ||
| System.out.println("Введите данные 3-х автомобилей для начала гонки.\nВ этой гонке только одно правило: Допускаются автомобили со скоростью не выше 250 км/ч"); | ||
| } | ||
| if(carList.size() < 3) { | ||
| addCars(); | ||
| } else { | ||
| this.start(carList); | ||
| carList.clear(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| public void addCars() | ||
| { | ||
| System.out.println("Введите название " + (carList.size() + 1) + "-го автомобиля"); | ||
| String name = scanner.next(); | ||
|
|
||
| System.out.println("Введите скорость автомобиля '"+ name +"' (0-250)"); | ||
| int speed = scanner.nextInt(); | ||
| if (speed >= 0 && speed <= 250) { | ||
| carList.add(new Car(name, speed)); | ||
|
|
||
| } else if(speed < 0) { | ||
| System.out.println("С этим автомобилем что-то не так. Данный автомобиль дисквалифицирован."); | ||
| } else { | ||
| System.out.println("Превышена максимальная скорость автомобиля. Данный автомобиль дисквалифицирован."); | ||
| } | ||
| } | ||
| public void start(ArrayList<Car> carList) | ||
| { | ||
| for(int i = 3; i > 0; i--) { | ||
| try { | ||
| System.out.println(i); | ||
| Thread.sleep(1000); | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| System.out.println("СТАРТ!"); | ||
| this.rounds(); | ||
| this.finish(carList); | ||
| } | ||
| private void finish(ArrayList<Car> carList) | ||
| { | ||
| for(Car item: carList) { | ||
| this.newLeader(item.name,item.speed); | ||
| } | ||
| System.out.println("ФИНИШ!"); | ||
| System.out.println("Подедитель гонки - "+this.leader+"!"); | ||
| System.out.println("Для выхода напишите команду 'exit'\nДля продолжения гонок введите 'start'"); | ||
|
|
||
| } | ||
|
|
||
| } |
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.