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
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| class Rubles { | ||
| public static String GetRubleAddition(int num) { | ||
| int preLastDigit = num % 100 / 10; | ||
| if (preLastDigit == 1) { | ||
| return "рублей"; | ||
| } | ||
| switch (num % 10) { | ||
| case 1: | ||
| return "рубль"; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| return "рубля"; | ||
| default: | ||
| return "рублей"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,58 @@ | ||
| // dev branch for Y.Practicum | ||
| import java.util.Scanner; | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько персон разделить счет?"); //Количество людей | ||
|
|
||
| while (true) { | ||
| int people = scanner.nextInt(); | ||
| if (people == 1) { | ||
| System.out.println("Хотите разделить свою еду?\nДобавьте больше людей!"); | ||
| } | ||
| if (people < 1) { | ||
| System.out.println("Неправильное количество!\nДобавьте больше людей!"); | ||
| } | ||
| if (people > 1) { | ||
| System.out.println("Давайте подсчитаем!"); | ||
| Double value =(GroceryList.Product()/people); | ||
| String result = String.format("%.2f",value); | ||
|
|
||
| System.out.println("Сумма с человека: "+result+" "+Rubles.GetRubleAddition((int)Math.floor(value))); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| class GroceryList { | ||
|
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. Лучше вынести в отдельный файл |
||
|
|
||
| public static double Product() { | ||
|
|
||
| double sum = 0.0; | ||
| StringBuilder products = new StringBuilder(("Добавить блюда")); //Обьявить блюда | ||
|
|
||
| while (true) { | ||
| String name; | ||
| Scanner nameProduct = 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. Лучшее переиспользовать инстанс |
||
| System.out.println("Введите название блюда"); // Ввести название блюда | ||
| name = nameProduct.nextLine(); | ||
|
|
||
| if (name.equalsIgnoreCase("Завершить")) { //Подсчет итога | ||
| System.out.println(products); | ||
| break; | ||
| } | ||
|
|
||
| double price; | ||
| System.out.println("Введите стоимость блюда"); // Ввести стоимость | ||
| price = nameProduct.nextDouble(); | ||
|
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 (price > 0) { | ||
| products.append("\n").append(name).append(" по цене ").append(price); | ||
| sum += price; | ||
| System.out.println("Блюдо добавлено"); | ||
| } | ||
|
|
||
| } | ||
| return sum; | ||
| } | ||
| } | ||
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.
Scannerесть удобный методhasNextInt, можно сразу узнать без дополнительных проверок возможно ли интерпретировать строку какint. В данном случае без этой проверки при введение пользователем строки приложение выбросит исключение