Repository navigation
первый Pull Request #123
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
первый Pull Request #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,44 @@ | ||
| class Calculator { | ||
| import java.lang.Math; | ||
| public class Calculator { | ||
| Product product; | ||
| double fullPrice = 0; | ||
| String listOfProducts = ""; | ||
| double fullPriceSharing = 0; | ||
| String rubles = ""; | ||
|
|
||
| int friendsCount; | ||
|
|
||
| String cart = "Добавленные товары:"; | ||
| double totalPrice = 0; | ||
|
|
||
| Calculator(int friendsCount) { | ||
| this.friendsCount = friendsCount; | ||
| Calculator(Product product) { | ||
| this.product = product; | ||
| } | ||
|
|
||
| void addItem(Item item) { | ||
| totalPrice += item.price; | ||
| cart = cart + "\n" + item.name; | ||
| void addProduct (Product product) { | ||
| fullPrice += product.getPrice(); | ||
| listOfProducts += product.getName() + "\n"; | ||
| } | ||
|
|
||
| System.out.println(item.name + " в корзине"); | ||
| double everyonePays (int persons){ | ||
| fullPriceSharing = fullPrice / persons; | ||
| return fullPriceSharing; | ||
| } | ||
|
|
||
| double divideSum() { | ||
| return totalPrice / friendsCount; | ||
| String ending (double fullPriceSharing){ | ||
| if (Math.floor(fullPriceSharing) >= 11 && Math.floor(fullPriceSharing) <=19){ | ||
| rubles = "Рублей"; | ||
| } | ||
| else { | ||
| switch ((int) Math.floor(fullPriceSharing % 10)) { | ||
| case 1: | ||
| rubles = "Рубль"; | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| rubles = "Рубля"; | ||
| break; | ||
| default: | ||
| rubles = "Рублей"; | ||
| break; | ||
| } | ||
| } | ||
| return rubles; | ||
| } | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,45 +5,68 @@ public class Main { | |
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| int friendCount; | ||
| int numberOfPersons = 0; | ||
| String name = ""; | ||
| double price = 0.0; | ||
| Product random = new Product(name, price); | ||
| Calculator calc = new Calculator(random); | ||
|
|
||
| while (true) { | ||
| System.out.println("На сколько человек необходимо разделить счет?"); | ||
| friendCount = scanner.nextInt(); | ||
|
|
||
| if (friendCount > 1) { | ||
| break; | ||
| } else if (friendCount == 1) { | ||
| System.out.println( | ||
| "Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы."); | ||
| } else { | ||
| System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); | ||
| System.out.println("На скольких человек нужно разделить счёт?"); | ||
| if (scanner.hasNextInt()) { | ||
| numberOfPersons = scanner.nextInt(); | ||
|
|
||
| if (numberOfPersons > 1) { | ||
| break; | ||
| } else if (numberOfPersons == 1) { | ||
| System.out.println("Вы один, счёт делить не нужно)"); | ||
| } else { | ||
| System.out.println("Некорректное значение"); | ||
| } | ||
| } | ||
| else{ | ||
| System.out.println("Некорректное значение"); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| Calculator calculator = new Calculator(friendCount); | ||
| System.out.println("Введите название продукта"); | ||
| scanner.nextLine(); | ||
| name = scanner.nextLine(); | ||
|
|
||
| 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("Введите стоимость продукта в формате XX,XX"); | ||
| if(scanner.hasNextDouble()) { | ||
| price = scanner.nextDouble(); | ||
| if(price >= 0) { | ||
| Product UserInput = new Product(name, price); | ||
|
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. переменные принято именовать с маленькой буквы |
||
| calc.addProduct(UserInput); | ||
|
|
||
| System.out.println( | ||
| "Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления"); | ||
| String answer = scanner.next(); | ||
|
|
||
| if (answer.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| System.out.println("Продукт успешно добавлен"); | ||
| System.out.println("Не хотите добавить еще один продукт?"); | ||
| System.out.println("Введите название продукта или"); | ||
| System.out.println("Введите \"Завершить\", чтобы завершить процесс добавления товаров"); | ||
| scanner.nextLine(); | ||
| String answer = scanner.nextLine(); | ||
| if (answer.equalsIgnoreCase("завершить")) { | ||
| break; | ||
| } else { | ||
| name = answer; | ||
| } | ||
| } | ||
| else{ | ||
| System.out.println("Некорректное значение"); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
| else{ | ||
| System.out.println("Некорректное значение"); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
|
|
||
| double result = calculator.divideSum(); | ||
| Formatter formatter = new Formatter(); | ||
|
|
||
| System.out.println(calculator.cart); | ||
| System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result)); | ||
| calc.everyonePays(numberOfPersons); | ||
| calc.ending(calc.fullPriceSharing); | ||
| System.out.println("Добавленные товары:\n" + calc.listOfProducts); | ||
| System.out.println(String.format("Каждый должен заплатить %.2f" + " %s", calc.fullPriceSharing, calc.rubles)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| public class Product { | ||
| double price; | ||
| String name; | ||
|
|
||
| Product(String name, double price){ | ||
| this.name = name; | ||
| this.price = price; | ||
| } | ||
| String getName (){ | ||
| return this.name; | ||
| } | ||
| double getPrice (){ | ||
| return this.price; | ||
| } | ||
| } | ||
|
|
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.
Можно заменить на switch case, что бы сделать код более читаемым