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"
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.

83 changes: 52 additions & 31 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,68 @@
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();

if (friendCount > 1) {
break;
} else if (friendCount == 1) {
System.out.println(
"Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы.");
} else {
System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз.");
}
}
Scanner scanner = new Scanner(System.in);
Car[] cars = new Car[3];

Calculator calculator = new Calculator(friendCount);
for (int j = 0; j < 3; j++) {

while (true) {
System.out.println("Введите название товара");
System.out.println("Введите название машины № " + (j + 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("Введите скорость машины № " + (j + 1));
int speed = 0;

System.out.println(
"Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления");
String answer = scanner.next();
while (scanner.hasNext()) {
if (scanner.hasNextInt()) {
speed = scanner.nextInt();

if (answer.equalsIgnoreCase("Завершить")) {
break;
if (speed >= 0 && speed <= 250) {
break;
}
else {
System.out.println("Введите корректное значение скорости от 0 до 250 км/час");
}
}
else {
String s = scanner.next();
System.out.println("Введите корректное значение");
}
}

cars[j] = new Car(name, speed);
}
scanner.close();

String winner = cars[0].name;
int winDistance = cars[0].countDistance();

double result = calculator.divideSum();
Formatter formatter = new Formatter();
for (int i = 0; i < 3; i++) {

System.out.println(calculator.cart);
System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result));
if (cars[i].countDistance() > winDistance) {
winDistance = cars[i].countDistance();
winner = cars[i].name;
}
}
System.out.println("Победитель гонки: " + winner);
}
}


class Car {

String name;
int speed;

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

int distance = 0;

int countDistance() {
distance = 24 * speed;
return distance;
}
}