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
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));
}
}
25 changes: 22 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");

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

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

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