-
Notifications
You must be signed in to change notification settings - Fork 0
Это мой Pull Request #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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| public class Automobile { | ||
|
|
||
| String name; | ||
| int speed; | ||
|
|
||
|
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍏 Лучше пометить эти поля как private и добавить для них геттеры/сеттеры. О них можно почитать здесь https://javarush.com/groups/posts/1928-getterih-i-setterih |
||
| public Automobile(String name, int speed) { | ||
| this.name = name; | ||
| this.speed = speed; | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,45 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| int friendCount; | ||
| while (true) { | ||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| friendCount = scanner.nextInt(); | ||
| final int AMOUNT_CARS = 3; | ||
| final int MAX_SPEED = 250; | ||
| final int MIN_SPEED = 0; | ||
|
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Круто, что вынес в константы эти значения |
||
|
|
||
| if (friendCount > 1) { | ||
| break; | ||
| } else if (friendCount == 1) { | ||
| System.out.println( | ||
| "Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы."); | ||
| } else { | ||
| System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); | ||
| } | ||
| } | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("Приветствую на гонке «24 часа Ле-Мана»!"); | ||
| ArrayList<Automobile> autoList = new ArrayList<>(); | ||
|
|
||
| Calculator calculator = new Calculator(friendCount); | ||
| for (int i = 0; i < AMOUNT_CARS; i++) { | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите название товара"); | ||
| System.out.println("— Введите название машины №" + (i + 1) + ":"); | ||
| String name = scanner.next(); | ||
|
|
||
| System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10.45, 11.40]"); | ||
| double price = scanner.nextDouble(); | ||
|
|
||
| calculator.addItem(new Item(name, price)); | ||
|
|
||
| System.out.println( | ||
| "Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления"); | ||
| String answer = scanner.next(); | ||
|
|
||
| if (answer.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| System.out.println("— Введите скорость машины №" + (i + 1) + " в параметрах от " + MIN_SPEED + " по " + MAX_SPEED + " км/ч:"); | ||
| while (true) { | ||
| String input = scanner.nextLine(); | ||
| if (input.isEmpty()) { | ||
| continue; | ||
| } | ||
| try { | ||
| int speed = Integer.parseInt(input); | ||
| if (speed >= MIN_SPEED && speed <= MAX_SPEED) { | ||
| Automobile auto = new Automobile(name, speed); | ||
| autoList.add(auto); | ||
| Race.getWinner(auto); | ||
| System.out.println("Приветствуем нового учавстника гонки: \n" + autoList.get(i).name + " со скоростью " + autoList.get(i).speed); | ||
| break; | ||
| } else { | ||
| System.out.println("Введена скорость вне допустимого диапозона. Попробуй ещё. \nЯ в тебя верю, на этот раз у тебя обязательно получится!"); | ||
| } | ||
| } catch (NumberFormatException error) { | ||
| System.out.println("Введены некорректное значение скорости. Попробуй ещё. \nЯ в тебя верю, на этот раз у тебя обязательно получится!"); | ||
|
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Здорово, что обработал некорректный ввод |
||
| } | ||
| } | ||
| } | ||
|
|
||
| double result = calculator.divideSum(); | ||
| Formatter formatter = new Formatter(); | ||
|
|
||
| System.out.println(calculator.cart); | ||
| System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result)); | ||
| System.out.println("\nПриветствуем победителя гонки: \n" + Race.winner + " проехал " + Race.distance + " км."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| public class Race { | ||
| static int distance = 0; | ||
| static String winner = ""; | ||
|
|
||
| public static void getWinner(Automobile auto) { | ||
| //Дистанция = время (24) * скорость (вводит пользователь) | ||
| if (distance < 24 * auto.speed) { | ||
| distance = 24 * auto.speed; | ||
| winner = auto.name; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 Некоторые лишние изменения вошли в пуллреквест из-за неправильной работы с ветками.
Оставлю памятку по работе с ветками на будущее