-
Notifications
You must be signed in to change notification settings - Fork 0
Практическая работа No1 #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
Changes from all commits
e1f6893
c521234
2567102
a590ea7
217b08c
545868e
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,60 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculate { | ||
|
|
||
| public static void product(double person) { | ||
|
|
||
| String food = ""; | ||
| double price = 0.0; | ||
|
|
||
| while (true) { | ||
| System.out.println("Для добавления товара введите название продукта\nДля завершения программы введите \"Завершить\""); | ||
| Scanner scanner = new Scanner(System.in); | ||
| String inputFood = scanner.next(); | ||
| double itog = 0; | ||
|
|
||
| if (inputFood.equalsIgnoreCase("Завершить")) { | ||
| itog = (int) (price / person); | ||
| System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " " + Matsh.floover(itog)); | ||
| break; | ||
|
|
||
| } else { | ||
| System.out.println("Введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\""); | ||
| while (!scanner.hasNextInt()) { | ||
| System.out.println("Некорректное значение, введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\""); | ||
| scanner.next(); | ||
| } | ||
| float inputPrice = (float) scanner.nextDouble(); | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| food = food + "\n" + inputFood; | ||
| price = price + inputPrice; | ||
|
|
||
| System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(itog)); | ||
|
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. Здесь выводится стоимость товара - price, но расчет окончания слова Рубль берется для числа itog, а должна быть одна и та же переменная 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. Наставница передала твой вопрос, что я имела в виду: |
||
| } | ||
| } | ||
| } | ||
|
|
||
| static class Matsh { | ||
|
|
||
| public static String floover(double price) { | ||
|
|
||
| int amount = (int) price; | ||
|
|
||
| if (amount > 100) | ||
| amount %= 100; | ||
|
|
||
| if (amount > 20) | ||
| amount %= 10; | ||
|
|
||
| switch (amount) { | ||
| case 1: | ||
| return "Рублю"; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| return "Рубля"; | ||
| default: | ||
| return "Рублей"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Menu { | ||
| public static void main(String[] args) { | ||
| inputParameters(); | ||
|
|
||
| } | ||
| public static void inputParameters(){ | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько персон делить чек?"); | ||
| int person = 0; | ||
|
|
||
| while (!scanner.hasNextInt()) { | ||
| System.out.println("Некорректное значение для подсчёта, попробуйте еще раз"); | ||
| scanner.next(); | ||
| } | ||
| while (true) { | ||
| person = scanner.nextInt(); | ||
| if (person > 1) { | ||
| System.out.println("Давайте посчитаем!"); | ||
| Calculate.product(person); | ||
| } | ||
| if (person == 1) { | ||
| System.out.println("Вы оплачиваете счет сами"); | ||
| Calculate.product(person); | ||
| } | ||
| if (person < 1) { | ||
| System.out.println("Некорректное значение для подсчёта, попробуйте еще раз"); | ||
|
|
||
|
|
||
| } | ||
| } | ||
| } | ||
| } |