Repository navigation
PR Добренков Проверочная работа №1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5cf9a08
ef7b51b
37adb72
4c4ff3f
bf86c9e
9079e27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
|
|
||
|
|
||
| public class Formatter { | ||
| static String a = ""; | ||
| static void FormatterRubles() { | ||
| int floor = (int) Math.floor(Main.sumMain); | ||
| if (floor % 100 >= 11 && floor % 100 <= 14) { | ||
| a = "рублей"; | ||
| } else if (floor % 10 == 1) { | ||
| a = "рубль"; | ||
| } else if (floor % 10 >= 2 && floor % 10 <= 4) { | ||
| a = "рубля"; | ||
| } else if (floor % 10 >= 5 && floor % 10 <= 8) { | ||
| a = "рублей"; | ||
| }else if (floor % 9 == 0) { | ||
| a = "рублей"; | ||
| } else if (floor % 10 == 0) { | ||
| a = "рублей"; | ||
| }}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,37 @@ | ||
| import java.util.InputMismatchException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| static double sumMain = 0; | ||
| static String strProductsMain = ""; | ||
| private static int humans; | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| } | ||
| } | ||
| Scanner scanner = new Scanner(System.in); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. некритичное замечание: хорошей практикой является делать вызов scanner.close() после того, как сканнер больше не используется. Это необходимо для того, что бы этот объект не потреблял ресурсы, тогда когда это уже не требуется. |
||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| while (true) { | ||
| System.out.println("Введите целое число"); | ||
| try { | ||
| humans = scanner.nextInt(); | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("Не целое число"); | ||
| scanner.nextLine(); | ||
| } | ||
| if (humans > 1) { | ||
| break; | ||
| } else if (humans == 1) { | ||
| System.out.println("Нет смысла ничего считать и делить :-)"); | ||
| return; | ||
| } else { | ||
| System.out.println("Некорректное значение для подсчёта!"); | ||
| } | ||
| } | ||
| Products.productCount(); | ||
| strProductsMain += Products.strProducts; | ||
| System.out.println("Добавленные товары: " + strProductsMain); | ||
| sumMain += Products.sum; | ||
| sumMain = sumMain / humans; | ||
| String result = String.format("%.2f", sumMain); | ||
| Formatter.FormatterRubles(); | ||
| System.out.println("Всем необходиомо заплатить по " + result + " " + Formatter.a + "."); | ||
| scanner.close();}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import java.util.InputMismatchException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Products { | ||
| static String strProducts = ""; | ||
| static double sum = 0; | ||
| static double productPrice; | ||
| static void productCount() { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Некритично: то же самое замечание по поводу Scanner: лучше вызвать close() после окончания использования сканнера для высвобождения ресурсов системы. |
||
| while (true) { | ||
| System.out.println("Хотите добавить товар?"); | ||
| String productInput = scanner.next(); | ||
| switch (productInput.toLowerCase()) { | ||
| case "да": | ||
| while (true) { | ||
| System.out.println("Введите название товара."); | ||
| String productName = scanner.next(); | ||
| strProducts = strProducts.concat("\n").concat(productName); | ||
| while (true) { | ||
| System.out.println("Введите стоимость товара."); | ||
| try { | ||
| productPrice = scanner.nextDouble(); | ||
| }catch (InputMismatchException b){ | ||
| System.out.println("Введено не число."); | ||
| scanner.nextLine(); | ||
| } | ||
| if (productPrice > 0) { | ||
| break; | ||
| } else if (productPrice < 0) { | ||
| System.out.println("Стоимость не может быть отрицательной!"); | ||
| } | ||
| } | ||
| System.out.println("Товар добавлен!"); | ||
| sum = sum + productPrice; | ||
| System.out.println("Хотите добавить еще товар? (Введите \"Завершить\" ,чтобы завершить процесс добавления товаров.)"); | ||
| String productInput2 = scanner.next(); | ||
| switch (productInput2.toLowerCase()) { | ||
| case "да": | ||
| break; | ||
| case "нет": | ||
| return; | ||
| case "завершить": | ||
| return; | ||
| default: | ||
| while (true) { | ||
| System.out.println("Введите \"Да\" ,чтобы добавить товар.\nВведите \"Завершить\" ,чтобы завершить процесс добавления товаров."); | ||
| String productInput3 = scanner.next(); | ||
| if (productInput3.equalsIgnoreCase("да")) { | ||
| break; | ||
| } else if (productInput3.equalsIgnoreCase("Завершить")) { | ||
| return; | ||
| } else { | ||
| } | ||
| } | ||
| } | ||
| } | ||
| case "нет": | ||
| return; | ||
| default: | ||
| System.out.println("Введите да или нет!"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
некритичное замечание: кажется, что здесь опечатка и имелось ввиду
floor % 10 ==9? В этом случае можно было изменить предыдущую ветку сравнеия и убрать эту :else if (floor % 10 >= 5 && floor % 10 <=9) { a = "рублей"; }