Skip to content
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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dependencyResolutionManagement {
mavenCentral()
}
}
rootProject.name = "BillCalculator"
rootProject.name = "Java-Module-Project"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏 Некоторые лишние изменения вошли в пуллреквест из-за неправильной работы с ветками.
Оставлю памятку по работе с ветками на будущее

Снимок экрана 2024-07-06 в 11 26 47

10 changes: 10 additions & 0 deletions src/main/java/Automobile.java
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
}
}
22 changes: 0 additions & 22 deletions src/main/java/Calculator.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/Formatter.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/Item.java

This file was deleted.

64 changes: 30 additions & 34 deletions src/main/java/Main.java
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 + " км.");
}
}
12 changes: 12 additions & 0 deletions src/main/java/Race.java
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;
}
}
}