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

Newdev #2

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
bezFantazee wants to merge 2 commits into main
base: main
Choose a base branch
Loading
from newdev
Open
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
60 changes: 58 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,62 @@
import java.util.Scanner;
import java.util.InputMismatchException;


public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner scanner = new Scanner(System.in);
Race leader = new Race();
System.out.println("Необходимо заполнить информацию о 3-х автомобилях\n");
for(int i=1; i<=3; i++){
System.out.print(i+" автомобиль\nназвание: ");
String carName = scanner.next();
System.out.print("скорость(<=250): ");
int carSpeed = 0;
while(true){
try{
carSpeed = scanner.nextInt();
if(carSpeed>0 && carSpeed<=250) break;
else if(carSpeed<0) System.out.print("Скорость не может быть отрицательной. Введите число больше 0: ");
else System.out.print("Скорость должна быть <=250. овторите ввод: ");
}
catch (InputMismatchException e){
System.out.print("Ошибка: введите целое число: ");
scanner.next();
}
}
Car newCar = new Car(carName, carSpeed);
leader = leader.findLeader(newCar.name, newCar.speed);
}
System.out.println("Самая быстрая машина: " + leader.leaderName);
}
}

class Car {
String name;
int speed;
Car(String name, int speed){
this.name = name;
this.speed = speed;
}
}

class Race{
String leaderName;
int leaderSpacing;
Race(String leaderName, int spacing){
this.leaderName = leaderName;
this.leaderSpacing = spacing;
}
Race(){
leaderName = "";
leaderSpacing = 0;
}
}
public Race findLeader(String carName, int carSpeed){
int carSpacing = carSpeed*24;
if(leaderSpacing<carSpacing){
return new Race(carName, carSpacing);
}
return new Race(leaderName, leaderSpacing);
}
}

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