Skip to content
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

Sprint2ok #298

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/main/java/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Car {
final String brand;
final int speed;

Car (String brand, int speed){
this.brand = brand;
this.speed = speed;
}
}
29 changes: 28 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
System.out.println("24 часа Ле-Мана");
Scanner scanner = new Scanner(System.in);

int numberOfCars = 3;
Race rs = new Race();

for (int i = 0; i<numberOfCars; i++){
System.out.println("— Введите название машины № " + (i+1));
String brand = scanner.next();
for(;true;) {
System.out.println("— Введите скорость машины № " + (i + 1));
if (scanner.hasNextInt()){
int speed = scanner.nextInt();
if (speed>0 && speed<=250){
rs.addCarToRace(new Car(brand,speed));
break;
} else {
System.out.println("— Неправильная скорость ");
}
} else {
System.out.println("— Неправильная скорость, не число");
scanner.next();
}
}
}
System.out.println("Самая быстрая машина: " + rs.getWinner());
scanner.close();
}
}
19 changes: 19 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.ArrayList;

public class Race {
String leaderCarName = "";
int maxDist = 0;

void addCarToRace(Car c){
int newDist = 24*c.speed;
if (newDist>maxDist){
leaderCarName = c.brand;
maxDist = newDist;
}
}

String getWinner (){
return leaderCarName;
}

}