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

Решение Проектной работы No1 #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
KateDesu wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from dev
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
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Car {
public String carName;
int speed;

Car(String carName, int speed) {
this.carName=carName;
this.speed=speed;
}
}
13 changes: 13 additions & 0 deletions src/main/java/CarRace.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class CarRace {
public static String leader="";
private static int distance=0;

public static void getLeader(Car car) {
if ((car.speed*24)>distance) {
distance =(car.speed*24);
leader=car.carName;
}

System.out.println("Самая быстрая машина: " + leader+"\n");
}
}
43 changes: 41 additions & 2 deletions src/main/java/Main.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
public static Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {
System.out.println("Hello world!");
int countCar=3;
ArrayList<Car> cars = new ArrayList<>();

for (int i=0; i<countCar; i++) {
cars.add(addCar(i+1));
CarRace.getLeader(cars.get(i));
}
}

public static Car addCar(int numberCar) {
short minSpeed=1;
short maxSpeed=250;
short carSpeed;
String error="Неправильная скорость";

System.out.println("- Введите название машины No"+numberCar);
String nameOfCar=scanner.next();

while(true) {
System.out.println("- Введите скорость машины No"+numberCar);
String str = scanner.next();

try {
carSpeed = Short.parseShort(str);
} catch (Exception ex) {
System.out.println(error);
continue;
}

if (carSpeed >= minSpeed && carSpeed <= maxSpeed) {
return new Car(nameOfCar, carSpeed);

} else {
System.out.println(error);
}
}
}
}
}

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