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/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ 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..ac216bc --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.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..611e7c8 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..43c9188 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 1b1d075..d45c8b6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'java' -sourceCompatibility = 1.8 +sourceCompatibility = 14 version = '1.0' repositories { @@ -8,3 +8,4 @@ repositories { dependencies { } +targetCompatibility = JavaVersion.VERSION_14 diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java new file mode 100644 index 0000000..e03e4d4 --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,84 @@ +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Scanner; + +public class Calculator { + + private final int countPeople; + private double sum; + private double price; + + private final List goods = new ArrayList(); + + Calculator(int countPeople) { + + this.countPeople = countPeople; + + } + + public void total() { + + DecimalFormat decimalFormat = new DecimalFormat("#.##"); + + System.out.println("Общая сумма " + decimalFormat.format(sum)+ " " + Product.GetRubleAddition(sum)); + System.out.println("С человека " + decimalFormat.format(sum / countPeople) + " " + + Product.GetRubleAddition(sum / countPeople)); + + } + + public void start(Scanner sc) { + + while (true) { + System.out.println("Введите название товара"); + + String name = sc.next(); + + System.out.println("Введите цену товара"); + + while (true) { + + Scanner scDouble = new Scanner(System.in).useLocale(Locale.US); + + if (scDouble.hasNextDouble()){ + + price = scDouble.nextDouble(); + sum += price; + break; + + }else{ + System.out.println("Неверный ввод, введите цену в формате 00.00"); + } + + + } + + Product product = new Product(name, price); + goods.add(product); + System.out.println("Товар добавлен, введи Завершить, чтобы закончить ввод"); + String check = sc.next(); + if (check.equalsIgnoreCase("Завершить")) { + + break; + + } + + + } + } + + public void result() { + System.out.println("Добавленные товары: "); + for (Product product : goods + ) { + product.info(); + + + } + + + } + + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..6df6a05 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,40 @@ +import java.util.Locale; +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + final String DIGITS = "\\d+"; + System.out.println("Привет, сколько вас человек?"); + + int countPeople; + Scanner sc = new Scanner(System.in).useLocale(Locale.US); + while (true) { + + String countPeople1 = sc.nextLine(); + + if (countPeople1.matches(DIGITS)) { + countPeople = Integer.parseInt(countPeople1); + if (countPeople <= 1) { + System.out.println("Недостаточно человек"); + } else { + + //double sum = 0; + Calculator calculator = new Calculator(countPeople); + calculator.start(sc); + calculator.result(); + calculator.total(); + break; + } + + } + else { + System.out.println("Доступен ввод только числа"); + } + + + + + } } } diff --git a/src/main/java/Product.java b/src/main/java/Product.java new file mode 100644 index 0000000..66888ef --- /dev/null +++ b/src/main/java/Product.java @@ -0,0 +1,35 @@ +public class Product { + String name; + double price; + + Product(String name, double price) { + this.name = name; + this.price = price; + } + + public void info() { + System.out.println("Товар " + name + " цена " + price + " " + GetRubleAddition(price)); + } + + public static String GetRubleAddition(Double value) { + + int num = value.intValue(); + + int preLastDigit = num % 100 / 10; + if (preLastDigit == 1) { + return "рублей"; + } + + switch (num % 10) { + case 1: + return "рубль"; + case 2: + case 3: + case 4: + return "рубля"; + default: + return "рублей"; + } + } +} + AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル