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

Auto racers #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
listikml wants to merge 1 commit into dev
base: dev
Choose a base branch
Loading
from devNew
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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

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