Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
org.gradle.warning.mode=all
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Sat Jul 23 10:15:32 MSK 2022
#Wed Nov 23 17:14:42 ALMT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
Expand Down
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"
73 changes: 73 additions & 0 deletions src/main/java/BillSplitter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
import java.util.Vector;

public class BillSplitter {
double totalAmount = 0;
int personCount;

List<Product> productList = new Vector<>();

BillSplitter(int count) {
personCount = count;
}

public String checkDouble(Double value) {
double d = value % 10;
String result = String.format("%.2f", value);
if (d==1)
result+=" рубль";
else if(d==2||d==3||d==4)
result+=" рубля";
else
result+=" рублей";
return result;
}

public void addProduct() {

String commandText;
String productName;
Double productPrice;

Scanner scanner = new Scanner(System.in);
scanner.useLocale(Locale.US);

while (true) {

System.out.print("Введите название товара: ");
productName = scanner.nextLine();

System.out.print("Введите стоимость в формате: \"'рубли.копейки' [10.45, 11.40]\": ");
if (scanner.hasNextDouble()) {
productPrice = scanner.nextDouble();
if (productPrice >= 0) {
productList.add(new Product(productName, productPrice));
totalAmount += productPrice;
} else {
System.out.println("Вы ввели некорректные данные цены, попробуйте заново");
scanner.nextLine();
continue;
}
} else {
System.out.println("Вы ввели некорректные данные цены, попробуйте заново");
scanner.nextLine();
continue;
}
System.out.println("Продукт " + productName + " был добавлен\nВы хотите добавить еще один товар?");
commandText = scanner.next();
scanner.nextLine();

if (commandText.equalsIgnoreCase("завершить"))
break;

}

System.out.println("Добавленные товары:");
for (int i = 0; i < productList.size(); i++) {
System.out.println(productList.get(i).title + "\t" + this.checkDouble(productList.get(i).price));
}
System.out.println("\nОбщая сумма на каждого человека: " + this.checkDouble(totalAmount / personCount));
}
}
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.

48 changes: 13 additions & 35 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,25 @@
public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
int count;

int friendCount;
while (true) {
System.out.println("На сколько человек необходимо разделить счет?");
friendCount = scanner.nextInt();
System.out.print("Введите количество пользователей: ");
if (scanner.hasNextInt()) {
count = scanner.nextInt();
if (count >= 1) {
break;
} else
System.out.println("Вы ввели некоректное число, попробуйте ещё раз");

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

Calculator calculator = new Calculator(friendCount);

while (true) {
System.out.println("Введите название товара");
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("Вы ввели некорректные данные, попробуйте ещё раз");
scanner.next();
}
}

double result = calculator.divideSum();
Formatter formatter = new Formatter();

System.out.println(calculator.cart);
System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result));
BillSplitter calculator = new BillSplitter(count);
calculator.addProduct();
}
}
8 changes: 8 additions & 0 deletions src/main/java/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Product {
String title;
Double price;
public Product(String name, double sum) {
title = name;
price = sum;
}
}