-
Notifications
You must be signed in to change notification settings - Fork 220
Калькулятор. Дубль 2. #76
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
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 |
|---|---|---|
| @@ -1,8 +1,25 @@ | ||
| import java.util.Scanner; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| Scanner scan = new Scanner(System.in); | ||
| System.out.println("На сколько человек вы хотели бы разделить чек?"); | ||
| try { | ||
|
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. Можно try-catch разместить внутри бесконечного цикла while, тогда при вводе строки пользователю будет позволено снова ввести число, без перезапуска программы (как сделано с числами меньше 1) |
||
| int numPeople = scan.nextInt(); | ||
| while (1 < 4) { | ||
|
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. Можно вместо |
||
| if (numPeople > 1) { | ||
| break; | ||
| } | ||
| System.out.println("Ошибка. Невозможно разделить чек на данное колличество людей. Попробуйте снова."); | ||
| numPeople = scan.nextInt(); | ||
| } | ||
|
|
||
| double check = calc.calculator() / numPeople; | ||
| System.out.println("Каждый человек должен заплатить: " + check + calc.ending(check)); | ||
| } catch (Exception e){ | ||
| System.out.println("Ошибка. Попробуйте снова."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class calc { | ||
|
|
||
| public static double calculator() { | ||
| Scanner scan2 = new Scanner(System.in); | ||
| Scanner scan3 = new Scanner(System.in); | ||
| Scanner scan4 = new Scanner(System.in); | ||
| for (String i = "Добавленные товары:"; 1 != 0; i = i) { | ||
|
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.
|
||
| for (double j = 0; j >= 0; j = j) { | ||
| System.out.println("Пожалуйста, введите название товара."); | ||
| String itemName = scan2.nextLine(); | ||
| System.out.println("Пожалуйста, введите цену товара в формате 'рубли.копейки' [10.45, 11.40]"); | ||
| double itemCost = scan3.nextDouble(); | ||
| System.out.println("Товар добавлен в список."); | ||
| i = i + "\n" + itemName + " " + itemCost + ending(itemCost); | ||
| j = j + itemCost; | ||
| System.out.println("Хотите ли бы вы завершить покупки?"); | ||
| String answer = scan4.nextLine(); | ||
| String stopWord = "Завершить"; | ||
| if (answer.equalsIgnoreCase(stopWord)) { | ||
| System.out.println(i); | ||
| System.out.println("Общая сумма покупок: " + j + ending(j)); | ||
| return j; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| public static String ending(double j){ | ||
| if(Math.floor(j) % 100 == 11 ^ Math.floor(j) % 100 == 12 ^ Math.floor(j) % 100 == 13 ^ Math.floor(j) % 100 == 14){ | ||
|
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.
|
||
| String stringe = " рублей"; | ||
| return stringe; | ||
|
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. Можно убрать переменную, написав просто |
||
| } | ||
| else { | ||
| double summ = Math.floor(j) % 10; | ||
| int remainder = (int) summ; | ||
| switch (remainder) { | ||
| case 1: | ||
| String string1 = " рубль"; | ||
| return string1; | ||
| case 2: | ||
| String string2 = " рубля"; | ||
| return string2; | ||
| case 3: | ||
| String string3 = " рубля"; | ||
| return string3; | ||
| case 4: | ||
| String string4 = " рубля"; | ||
| return string4; | ||
| default: | ||
| String stringdef = " рублей"; | ||
| return stringdef; | ||
| } | ||
| } | ||
| } | ||
| } | ||