Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Зайнуллин Артур ДЗ - 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
artcitycreativ wants to merge 10 commits into Yandex-Practicum:master
base: master
Choose a base branch
Loading
from artcitycreativ:master
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
10 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bin/main/Race.class
View file Open in desktop
Binary file not shown.
9 changes: 9 additions & 0 deletions src/main/java/Car.java
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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'");

}

}

AltStyle によって変換されたページ (->オリジナル) /