Repository navigation
Лабораторная работа 1. Цабут Ян #3
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
e1f6893
c521234
5a2609a
9316f14
1e1a1fc
3b8a936
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,20 @@ | ||
| class Calculator { | ||
| public class Calculator { | ||
| public static String complete(float costGeneral) { | ||
| String suffix; | ||
| int hundred = (int) Math.floor(costGeneral % 100); | ||
| if (hundred <= 14 && hundred >= 11) { | ||
| suffix = " рублей "; | ||
| } else { | ||
| int ten = hundred % 10; | ||
| if (ten == 1) { | ||
| suffix = " рубль "; | ||
| } else if (ten >= 2 && ten <= 4) { | ||
| suffix = " рубля "; | ||
| } else { | ||
| suffix = " рублей "; | ||
| } | ||
|
|
||
| int friendsCount; | ||
|
|
||
| String cart = "Добавленные товары:"; | ||
| double totalPrice = 0; | ||
|
|
||
| Calculator(int friendsCount) { | ||
| this.friendsCount = friendsCount; | ||
| } | ||
|
|
||
| void addItem(Item item) { | ||
| totalPrice += item.price; | ||
| cart = cart + "\n" + item.name; | ||
|
|
||
| System.out.println(item.name + " в корзине"); | ||
| } | ||
|
|
||
| double divideSum() { | ||
| return totalPrice / friendsCount; | ||
| } | ||
| return suffix; | ||
| } | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Products { | ||
| static String exit = "ЗАВЕРШИТЬ"; | ||
|
|
||
| public static void calc(int people) { | ||
| String product; | ||
| String allProducts = ""; | ||
| float costPrice; | ||
| float sumForall = 0.00f; | ||
|
|
||
| String close; | ||
| while (true) { | ||
| Scanner scanner2 = new Scanner(System.in); | ||
| System.out.println("Введите название товара"); | ||
| product = scanner2.nextLine(); | ||
| System.out.println("Товар " + product + " добавлен в счёт"); | ||
| System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [пример - 10.45, 11.40]"); | ||
| if (scanner2.hasNextFloat()) { | ||
| costPrice = scanner2.nextFloat(); | ||
| if (costPrice > 0) { | ||
| sumForall = sumForall + costPrice; | ||
| allProducts = allProducts + product + "\n"; | ||
| String sufForOne = Calculator.complete(costPrice); | ||
| String anotherOne = "Вы добавили: %s за %.2f%s\n"; | ||
| System.out.printf(anotherOne, product, costPrice, sufForOne); | ||
| System.out.println("Введите любой символ, если хотите добавить товар. В противном случае введите:'ЗАВЕРШИТЬ'"); | ||
| close = scanner2.next(); | ||
| if (close.equalsIgnoreCase(exit)) { | ||
| break; | ||
| } | ||
| } else { | ||
| System.out.println("Сумма указана неверно"); | ||
| } | ||
| } else { | ||
| System.out.println("Некорректный формат стоимости товара. Побробуйте ввести сумму ещё раз!"); | ||
| } | ||
|
|
||
| } | ||
| String suf = Calculator.complete(sumForall); | ||
| float forOneguest = sumForall/ people; | ||
| String lastSuf = Calculator.complete(forOneguest); | ||
|
|
||
| System.out.println("Вы купили:\n" + allProducts + "За " + String.format("%.2f", sumForall) + suf); | ||
| System.out.println("Каждый из гостей должен заплатить: " + String.format("%.2f", forOneguest) + lastSuf); | ||
| 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.
Лучшее переиспользовать инстанс сканнера, а не создавать каждый раз новый.