diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..05b5864
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+BillCalculator
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..6cec569
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..5d10be7
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java
new file mode 100644
index 0000000..a27f286
--- /dev/null
+++ b/src/main/java/Calculator.java
@@ -0,0 +1,49 @@
+import java.util.InputMismatchException;
+import java.util.Scanner;
+public class Calculator {
+
+ static void calculate(int people) {
+ String food = "";
+ double price = 0.0;
+
+ while (true) {
+ System.out.println("Введите название продукта, для выхода введите [Завершить]");
+ Scanner scanner = new Scanner(System.in);
+ String inputFood = scanner.next();
+
+ if (inputFood.equalsIgnoreCase("Завершить")) {
+ break;
+ } else {
+ food = food + inputFood + "\n";
+ price = price + price();
+ }
+
+ }
+ int rouble = (int) Math.round(price);
+ System.out.println("Добавленные товары:\n" + food);
+ String message = "Каждый человек должен заплатить %.2f" + " " + Main.declination(rouble);
+ System.out.println(String.format(message, (price / people)));
+ }
+
+
+ static double price() {
+ while (true) {
+ System.out.println("Введите цену в формате [руб,коп]");
+ double inputPrice = 0;
+ try {
+ double price = 0.0;
+ Scanner scanner = new Scanner(System.in);
+ inputPrice = scanner.nextDouble();
+ if (inputPrice <= 0){ + System.out.println("Неверное значение"); + } else { + return inputPrice; + } + } catch (InputMismatchException e) { + System.out.println("Неверное значение"); + } + } + } + + +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 964dbb0..7d5812c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,6 +1,41 @@ +import java.util.InputMismatchException; +import java.util.Scanner; public class Main { public static void main(String[] args) { // ваш код начнется здесь + int people; + while (true) { + System.out.println("На сколько человек нужно разделить счет?"); + Scanner scanner = new Scanner(System.in); + try { + people = scanner.nextInt(); + if (people>= 2) {
+ break;
+ } else {
+ System.out.println("Неверное значение");
+ }
+ }
+ catch (InputMismatchException e) {
+ System.out.println("Неверное значение");
+ }
+ }
+
+ Calculator calculator = new Calculator();
+ Calculator.calculate(people);
+
+ }
+ public static String declination(int rouble) {
+ switch (rouble % 10) {
+ case 1:
+ return "рубль";
+ case 2:
+ case 3:
+ case 4:
+ return "рубля";
+ default:
+ return "рублей";
+ }
}
}
+