Skip to content
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
35 changes: 35 additions & 0 deletions src/main/java/Auto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.Scanner;

public class Auto {
private String model;
private int speed;

public void inputAutoData() {
Scanner console = new Scanner(System.in);

System.out.println("Введите название автомобиля: ");
model = console.nextLine();

while (model.isEmpty()) {
System.out.println("Введено неверное значение.");
System.out.println("Введите название автомобиля: ");
model = console.nextLine();
}

System.out.println("Введите скорость автомобиля (от 0 до 250): ");
speed = console.nextInt();

while (speed < 0 || speed > 250) {
System.out.println("Введено неверное значение.");
System.out.println("Введите скорость автомобиля (от 0 до 250): ");
speed = console.nextInt();
}
}
public String getModel() {
return model;
}

public int getSpeed() {
return speed;
}
}
22 changes: 21 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import java.util.ArrayList;


public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Auto newAuto1 = new Auto();
newAuto1.inputAutoData();

Auto newAuto2 = new Auto();
newAuto2.inputAutoData();

Auto newAuto3 = new Auto();
newAuto3.inputAutoData();

ArrayList<Auto> members = new ArrayList<>();
members.add(newAuto1);
members.add(newAuto2);
members.add(newAuto3);

Race leaderRace = new Race();
Auto leader = leaderRace.findLeader(members);

System.out.println("Самая быстрая машина: " + leader.getModel());

}
}
22 changes: 22 additions & 0 deletions src/main/java/Race.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.ArrayList;

public class Race {
private final int hours = 24;

public Auto findLeader(ArrayList<Auto> members) {
int longestDestination = 0;
Auto leader = null;
for (int i = 0; i < members.size(); i++) {
int destination = hours * members.get(i).getSpeed();
if (destination > longestDestination) {
longestDestination = destination;
leader = members.get(i);
}
}
return leader;
}



}
//km = speed * h