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

Project work No1. Fastest car feature #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
Lemixus wants to merge 1 commit into dev
base: dev
Choose a base branch
Loading
from new-branch
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
11 changes: 11 additions & 0 deletions src/main/java/CarClass.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class CarClass {

String carName;
int speed;

public CarClass(String carName, int speed) {
this.carName = carName;
this.speed = speed;
}
}

47 changes: 45 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,49 @@
import java.util.Scanner;


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

RaceClass race = new RaceClass();

for (int i = 1; i <= 3; i++) {
int speed = 0;
String name = "";

while (true) {
System.out.println("Введите название машины " + i + ":");
name = scanner.nextLine().trim();

if (!name.isEmpty())
break;
else
System.out.println("Введите непустое название машины");

}

while (true) {
System.out.println("Введите скорость машины " + i + ":");
if (scanner.hasNextInt()) {
speed = scanner.nextInt();
if (speed > 0 && speed <= 250) {
scanner.nextLine();
break;
} else {
System.out.println("Введите скорость от 1 до 250");
}

} else {
System.out.println("Введите целое число");
scanner.next();
}
}

CarClass car = new CarClass(name, speed);
race.calculateRaceLeader(car);
}

System.out.println("Самая быстрая машина: " + race.leader);
scanner.close();
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/RaceClass.java
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class RaceClass {

String leader = "";
int leaderDistance = 0;

public void calculateRaceLeader(CarClass car) {
int time = 24;
int distance = time * car.speed;

if (distance > leaderDistance) {
leader = car.carName;
leaderDistance = distance;
}
}
}

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